InfoConnect for Airlines VBA Guide
Key Concepts / Navigating Sessions
In This Topic
    Navigating Sessions
    In This Topic

    You can use InfoConnect methods to navigate through your sessions:

    Navigating Through IBM Screens

    Navigating and Handling Branching in Open Systems Macros

    Navigating by Waiting for a Specified Time

    Finding and Moving to Screen Locations

    Navigating Through IBM Screens

    Using the NewScreenReady event along with the GetText function, you can identify specific screens when they are ready. You can then use the PutText and SendControlKey methods to enter commands that navigate to the next screen.

    Navigating through screens using the NewScreenReady event
    Copy Code
    Private Sub IbmScreen_NewScreenReady(ByVal sender As Variant)
      Dim ScreenID1, ScreenID2, ScreenID3, ScreenID4 As String
      Dim Rtn As ReturnCode
      ScreenID1 = ThisIbmScreen.GetText(1, 7, 4)     'ATM5 ispf
      ScreenID2 = ThisIbmScreen.GetText(2, 2, 6) 'option 2
    
      If ScreenID1 = "ATM5" Then
        Rtn = ThisIbmScreen.PutText2("ISPF", 24, 1)
        Rtn = ThisIbmScreen.SendControlKey(ControlKeyCode_Transmit)
      End If
      If ScreenID2 = "OPTION" Then
        Rtn = ThisIbmScreen.PutText2("2", 2, 15)
        Rtn = ThisIbmScreen.SendControlKey(ControlKeyCode_Transmit)
      End If
    End Sub
    

    Navigating and Handling Branching in Open Systems Macros

    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.

    Using WaitForStrings4
    Copy Code
    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 severalWaitForStrings 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 InfoConnect 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 Stop Recording.
    4. In the Recording Complete dialog box, choose to save the macro in the current document's project.
    5. In the Visual Basic Editor, open the Recording module for the project and find the strings referenced in the WaitForString method (for example, the "[11;14H" string shown below)
      Finding strings recorded for WaitForString3
      Copy Code
      '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 code sample
      Using the strings in the macro 
      Copy Code
      Public 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
         For i = 0 To 2
            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
      
         Next i
      
      End Sub
      

    Navigating by Waiting for a Specified Time

    You can navigate through IBM or Open Systems screens by waiting for a specified time between commands.

    This is useful for navigating Open Systems screens when you don't know the string values returned by the host (required by the WaitForStrings methods). It can also be used to navigate IBM screens.

    Example Title
    Copy Code
    'navigate to the screen you want to screen scrape
    rCode = screen.SendControlKey(ControlKeyCode_Transmit)
    rCode = screen.WaitForHostSettle(3000, 2000)'timeout followed by settle time
    rCode = screen.SendKeys("ISPF")
    rCode = screen.SendControlKey(ControlKeyCode_Transmit)
    rCode = screen.SendKeys("1")
    rCode = screen.SendControlKey(ControlKeyCode_Transmit)
    
    Example Title
    Copy Code
    'Send keys to navigate to screen that contains data
    'wait after keys are sent to make sure host screen is ready before sending more keys
    Set screen = terminal.screen
        
    screen.SendKeys "command"
    screen.SendControlKey ControlKeyCode_Return
    rCode = screen.WaitForHostSettle(3000) 'settle time
    screen.SendKeys "another command"
    

    Finding and Moving to Screen Locations

    You can use InfoConnect Search functions to find locations on the screen that you want to move your cursor to or use as a starting point for a selection.

    Finding and moving to a screen location
    Copy Code
    Sub SearchAndMove()
        Dim Point As ScreenPoint
        Dim returnC As ReturnCode
    
        'Find the screen position of the Command Field
        Set Point = ThisIbmScreen.SearchText1("COMMAND", 1, 1, FindOption_Forward)
              
        'Move the cursor to the field for this label (offsetting the label by 14 columns)
        returnC = ThisIbmScreen.MoveCursorTo1(Point.row, (Point.column + 14))
    
    End Sub
    
    Finding and moving to a screen location
    Copy Code
    Sub MoveTheCursor()
        Dim Point As ScreenPoint
       
        'Get the point on the display on which the data table starts
        Set Point = ThisScreen.SearchText("Month ", 1, 1, FindOptions_Forward)
    
        'Increment the row from the header row to first row of data and get the first row
        Debug.Print ThisScreen.GetText((Point.Row + 2), Point.Column, ThisScreen.DisplayColumns)
       
    End Sub
    

    See Also