ClickHandler

 

Description

When event handling (a.k.a. CallBack) is enabled, the ClickHandler procedure is used to sink the events. That is, whenever an event occurs, ClickHandler is called with the name of the form and control/event information.

To learn more about event handling, see the
CallBack Forms topic, the CallBack property described in the NewForm topic and the Events Handled topic.

Syntax

Sub sPrefixClickHandler ( sForm, sControl )

    'Your code should go here !

End Sub

Parameters

Part

Description

sPrefix

To enable event handling, you should have passed a second parameter to the Wscript.CreateObject method you use to connect to the WshDialog.Kit COM automation object. sPrefix must be identical to this second parameter.
For readability, it is good practice to add an underscore at the end

sForm

This parameter receives the name of the form on which the event occured

sControl

This parameter may contain one of the following values (more information can be found in the Events handled topic)

Event type

sControl value

Form level
events

Special keywords like "*ACTIVATE", "*CLOSE" and "*F1" through "*F12"

Control level
(default event).

The name of the control (for controls that handle only one event and for the default event of controls that handle multiple events)

Control level
(non-default
events)

A compound value, consisting of the name of the control, followed by the event name and (optional) additional data. The elements are separated by null characters

 

Example

Option Explicit

Dim oDlg

'Create the WshDialog.Kit object and specify oDlg_ as event sink prefix
Set oDlg = Wscript.CreateObject("WshDialog.Kit", "oDlg_")

'Code to add a form and controls and to show the form should go here:

'….

'-----------------------------------------------------------------------------------------------------------------
' oDlg_ClickHandler handles the events sent by the controls
'-----------------------------------------------------------------------------------------------------------------

Sub oDlg_ClickHandler(sForm, sControl)

    
Dim oFrm, oCtl

    
'Add this section to handle non-default events
    
Dim aEvent, sEvent, sData
    aEvent = Split(sControl, Chr(0))
    sControl = aEvent(0)
    If Ubound(aEvent) > 0 Then sEvent = aEvent(1)
    If Ubound(aEvent) > 1 Then sData = aEvent(2)

    
'Get a reference to the form and the control that raised the event
    
Set oFrm = oDlg.Frm(sForm)
    Set oCtl = oFrm.Ctl(sControl)

    
'Check from which form the event was raised
    Select Case Ucase(sForm)
    'Assume the form was not given a name (defaults to "")
    Case ""

        'Check which control raised the event
        'Assume there is a timer and OK and Cancel buttons
        Select Case Ucase(sControl)
        Case "*ACTIVATE"

            'Occurs when a form is activated (shown). Do initialization stuff
            oFrm.CloseBox = False
        Case "TIMER"
            
'Perform some actions, check for new mail for instance
        Case "LISTVIEW"
            
'Handle the events raised by a listview control
            Select Case sEvent
            Case ""    
'Default event (double-click or enter)
                
'sData is empty
            Case "AfterLabelEdit"
                
'sData contains the new string
            Case "ItemCheck"
                
'sData contains the index of the checked listitem
            Case "ItemClick"
                
'sData contains the index of the clicked listitem
            End Select
        Case "OK", "CANCEL"

            'Dismiss the form when the OK or Cancel button is clicked
            oFrm.Hide
        Case "*CLOSE"
            'Also dismiss the form when the closebox is clicked
            oFrm.Hide
        Case Else
            
'Ignore all other events. Do NOT use oFrm.Hide here, or any event
   
         'not handled above will dismiss the form
        End Select
    Case Else
        
'Handle other forms here (if any)
    End Select

End Sub