Add Method Example

This example macro creates three different wait-type objects, adds them to a Waits collection object, then waits for one of the wait-type objects in the collection to signal its event.

 

Sub Main

 ‘create the necessary System and Session objects…

 Dim sys as Object, sess as Object

 Set sys = CreateObject("Extra.System")

 ‘assumes an open session…

 Set sess = sys.ActiveSession

 

 ‘retrieve a new instance of a Waits collection object

 Dim waits as Object

 Set waits = sys.Waits

  

 ‘declare several object variables…

 Dim w1 as Object, w2 as Object, w3 as Object

 

 ‘Call methods to retrieve wait-type objects.

 ‘Note that it is crucial to use the "Set obj = …" syntax

 ‘when making these calls…otherwise wait-type objects

 ‘will not be returned, and the methods will wait synchronously,

 ‘in the order in which they were called…

 Set w1 = sess.Screen.WaitForString("Ready;")

 Set w2 = sess.Screen.WaitForCursor(10, 1)

 Set w3 = sess.WaitForDisconnect()

 

 ‘add the wait-type objects to the Waits collection object

 id1 = waits.Add(w1)

 id2 = waits.Add(w2)

 id3 = waits.Add(w3)

 

 ‘Wait for up to a minute to see which event occurs first

 retval = waits.Wait(60000)

 

 ‘Figure out which wait-type object fired its event,

 ‘causing the Wait method to return…

 

 Select Case retval

  case id1

   MsgBox "String we waited for was found!"

  case id2

   MsgBox "Cursor is now at desired location!"

  case id3

   MsgBox "Host session has been disconnected!"

  case 0

   MsgBox "Timed-out while waiting for an event!"

 End Select

 

End Sub