Sub WaitForSeveralHostStrings()
'These are the host strings to wait for. The string array needs to be 0 based.
Dim strArray(0 To 2) As String
strArray(0) = "Washington"
strArray(1) = "Adams"
strArray(2) = "Jefferson"
Dim retval As ReturnCode
Dim returnStringIndex As Long 'This is a 1 based number
'Use WaitForStrings4 after the macro does something (like entering the return key) to which the host reponds.
ThisScreen.SendControlKey ControlKeyCode_Return
'Wait 3 seconds for the strings and allow keystrokes while the wait is in progress.
retval = ThisScreen.WaitForStrings4(strArray(), 3000, returnStringIndex, WaitForOption_AllowKeystrokes)
If retval = ReturnCode_Success Then
'The returnStringIndex is now set.
'To determine which string in the zero based array was returned, subtract one from the returnedStringIndex.
Dim returnedString As String
returnedString = strArray(returnStringIndex - 1)
End If
End Sub
Function DetermineWhichScreenArrived() As Long
Dim i As Integer
Dim strArray(0 To 2) As String
Rem define the strings to wait for based on the values observed in a recorded macro.
strArray(0) = "demo" & CR 'We arrived at Apply Tax Screen
strArray(1) = CR & "enter your choice: " 'We arrived at Order Totals Screen
strArray(2) = ESC & "[23;30HYour choice: " 'We arrived at Shipments not Allowed to Location Screen
Dim retval As ReturnCode
Dim returnStringIndex As Long
Rem Wait for the strings in the strArray(), with a timeout of 3000 ms, and allow keystrokes to be entered while waiting.
retval = ThisScreen.WaitForStrings4(strArray(), 3000, returnStringIndex, WaitForOption_AllowKeystrokes)
Rem Print the string that was received.
If retval = ReturnCode_Success Then
Rem WaitForStrings requires a zero-based array parameter, but it returns a 1-based index of strings.
Rem Use a Select Case statement with 1-based values to determine the host response.
Select Case returnStringIndex
Case 1
Debug.Print "We arrived at Apply Tax Screen"
ThisScreen.SendKeys "3"
ThisScreen.SendControlKey ControlKeyCode_Return
Case 2
Debug.Print "We arrived at Order Totals Screen - Miscellaneous tests"
ThisScreen.SendKeys "demo"
ThisScreen.SendControlKey ControlKeyCode_Return
Case 3
Debug.Print "We arrived at Shipments not Allowed to Location Screen"
ThisScreen.SendControlKey ControlKeyCode_Return
End Select
End If
End Function
Sub Navigate()
'Navigate through the macro...
'When you navigate to a screen that returns different screens, depending on state, call DetermineWhichScreenArrived
Call DetermineWhichScreenArrived
End Sub