Show Contents / Index / Search

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

  1. Open Reflection 2008 and start a VT session.
  2. On the Tools tab, in the Macros group, click Record Macro.
  3. Perform the actions you want to automate with your macro and then click Record Macro to stop recording.
  4. In the Recording Complete dialog box, click Copy script to clipboard.
  5. 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)

  6. Specify to wait for these strings in your macro, as shown in the following sample:

    Sub DetermineWhatScreenArrived()
    Rem This sample shows how to define and wait for several strings to determine how the host responded.

    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) = "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

    Rem Define the Screen and terminal variables.

    Dim osCurrentScreen As Screen
    Dim osCurrentTerminal As Terminal


    Set osCurrentTerminal = ThisFrame.SelectedView.control
    Set osCurrentScreen = osCurrentTerminal.Screen

    Rem Send the VT PF1 key to finalize an order.
    osCurrentScreen.SendControlKey ControlKeyCode_PF1

    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 = osCurrentScreen.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"

    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