VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 17

Creating and Programming Custom WebItems - Dynamic Events for WebItems

You can get even more flexibility than either the Respond event of a WebItem or a custom WebItem event provides: You can program with dynamically defined WebItem events.

Dynamic WebItem event names are unknown at design time. The names of these events come from information that your code embeds in the HTML sent to the user’s browser at runtime. You detect the firing of a custom event in the UserEvent event procedure of the WebItem. UserEvent receives one string parameter, EventName. EventName contains, of course, the dynamic name of the custom event. To implement a dynamic event, follow these steps.

17.4 Implementing a Dynamic Event

  1. You can embed a two-argument call to URLFor in the WebClass_Start event procedure, as in step 3 of the preceding section. Instead of hard-coding an existing event’s name for the second argument to URLFor, however, you can pass a string for which you have defined no event as the second argument. This string can be either a hardcoded literal string or a string variable. This technique will dynamically vary the name of the event that fires when the user clicks the associated hyperlink.

  2. In the WebItem’s UserEvent procedure, you can vary the reaction to the user’s choice of the hyperlink based on the contents of the EventName parameter. In Listing 17.12, a Select Case structure in the UserEvent procedure traps for various dynamically generated event names and reacts differently, according to the name of the event.


Private Sub Service_UserEvent(ByVal EventName As String)

Select Case UCase$(Trim$(EventName))

strServiceColor = AVERAGECOLOR
strServiceDescription = "Average service."

strServiceColor = EXCELLENTCOLOR
strServiceDescription = "Excellent service."

Case "FAIR"
strServiceColor = FAIRCOLOR
strServiceDescription = "Fair service."

Case "GOOD"
strServiceColor = GOODCOLOR
strServiceDescription = "Good service."

Case "POOR"
strServiceColor = POORCOLOR
strServiceDescription = "Poor service."

End Select

End Sub

A common example of the power of dynamic events would be to generate an event whose name is based on the key field of a database record. Code in the UserEvent procedure would detect this event name representing the key field and use it to perform a lookup on the data.


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved