Example

This example uses DefineEvent to define an event which occurs every 5 seconds. EventDefined is used to return the event number. The While loop uses WaitEventNumber to wait for the event and display a message box. When the user cancels the message box, RemoveEvent is used to remove the event.

Sub DefinedEvent()

 Dim fiveSecondEvent As Integer 'event number

 Dim result As Integer 'Message box return

 

 With Session

  'Define a Time event to occur after a 5 second interval

  .DefineEvent rcNextEvent, rcTime, "5"

  

  'Use the EventDefined property to return the number of the

  'most recently defined event.

  fiveSecondEvent = .EventDefined

  

   'Wait for the event to occur until the user cancels.

   While .WaitEventNumber(fiveSecondEvent, 30)

    result = MsgBox("The event has occurred." & vbCrLf & vbCrLf & _

       "Press OK to wait for the next event. " & _

       "Press Cancel to terminate the event.", _

       vbOKCancel + vbInformation, "Five Second Event")

 

    'If the user cancelled, remove the event and quit

    If result = vbCancel Then

     .RemoveEvent fiveSecondEvent

     Exit Sub

    End If

   Wend

 End With

End Sub