Interacting with Hosts using VT Emulation
After sending data to a host, using VT or other non-block mode emulation, you must pause execution until you determine when the host has finished with its reply. Use the WaitForString method for this task. As soon as the final string in a host response has arrived, you can continue execution of your macro.
In some situations the host can reply with more than one response. Use the WaitForStrings method to determine which response the host has made and then apply it to decision branches in your macro.
WaitForStrings4() waits for a specified text string (or strings) to be received from the host.
Function object.WaitForStrings4(ref string[] text, int timeout, ref int stringidx, WaitForOption option)
where...
text is an array that specifies one or more strings for which to wait.
timeout is a wait timeout value (milliseconds). A value of 0 indicates wait indefinitely.
stringidx is a 1-based index indicating which string in the text array satisfied the condition. (For the first value in the array, stringidx = 1)
option specifies the WaitForOption. Multiple options can be combined using the OR operator.
Note The Reflection API includes several WaitForStrings functions with various levels of functionality. For more information, see the Reflection VBA Help.
To set up your macro, first record a macro to find out which strings you need to look for. (The macro recorder records the WaitForString method with the correct parameters for your host application.) Then set up a function that includes an array of these strings, as shown below.
To set up your macro to wait for VT host data
- Open Reflection 2008 and start a VT session.
- On the Tools tab, in the Macros group, click Record Macro.
- Perform the actions you want to automate with your macro and then click Record Macro to stop recording.
- In the Recording Complete dialog box, click Copy script to clipboard.
- Paste the script into a text editor and find the strings referenced in the WaitForString method (for example, the "[11;14H" string shown below)
'Wait for a string on the host screen before continuing returnValue = osCurrentScreen.WaitForString3(ESC & "[11;14H", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
- Specify to wait for these strings in your macro, as shown in the following sample:
Sub DetermineWhatScreenArrived()
Dim i As Integer Dim strArray(0 To 2) As String
strArray(0) = "11;14H" 'We arrived at Apply Tax Screen strArray(1) = "[11;15H" 'We arrived at Order Totals Screen strArray(2) = "[6;54H" 'We arrived at Shipments not Allowed to Location Screen
Dim osCurrentScreen As Screen Dim osCurrentTerminal As Terminal
Set osCurrentTerminal = ThisFrame.SelectedView.control Set osCurrentScreen = osCurrentTerminal.Screen
osCurrentScreen.SendControlKey ControlKeyCode_PF1
Dim retval As ReturnCode Dim returnStringIndex As Long
retval = osCurrentScreen.WaitForStrings4(strArray(), 3000, returnStringIndex, WaitForOption_AllowKeystrokes)
If retval = ReturnCode_Success Then
Select Case returnStringIndex Case 1 Debug.Print "We arrived at Apply Tax Screen"
Case 2 Debug.Print "We arrived at Order Totals Screen"
Case 3 Debug.Print "We arrived at Shipments not Allowed to Location Screen" End Select End If End Sub Next i End Sub
|