InfoConnect for Airlines VBA Guide
HowTos / Copy Data Between Terminal Sessions
In This Topic
    Copy Data Between Terminal Sessions
    In This Topic

    This macro copies text from a field on a screen in an InfoConnect demo program to a string variable. Then creates another demo session, navigates to a screen on the new session, and puts the text into a field on that session.

    This article contains tabbed content that is specific to each terminal type. Be sure to select the tab for your terminal type. (If you're not sure about which terminal to select, see Which Terminal Type are you Using?)

    To run this sample

    1. In a new Ibm 5250 terminal session, enter "demo:ibm5250.sim" in the Host name/IP address field.
    2. In the Visual Basic Editor, insert a module in the project folder and then copy the code into the module code pane.
    3. In the Ibm terminal session window, press enter to navigate to the next screen and then enter "kayak" to go the screen that has the data. 
    4. Run the macro.
    Copy text from one session to another
    Copy Code
    Sub CopyDataBetweenSessions()
       
        Dim rCode As ReturnCode
        Dim projectName As String
      
        'InfoConnect objects required to open a new session
        Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
        Dim view As Attachmate_Reflection_Objects.view
        Dim screen As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmScreen
        Dim terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
      
        'Get the text to copy from the current session
        projectName = ThisIbmScreen.GetText(1, 39, 5)
      
        'Get a handle to the existing application object (the workspace)
        Set app = GetObject("InfoConnect Workspace")
      
        'Create a new session and the view used to display the session
        Set terminal = app.CreateControl2("{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}")
                       
    
        terminal.HostAddress = "demo:ibm3270.sim"
      
        Set view = ThisFrame.CreateView(terminal)
    
        'Wait until Excel is ready
        While (view Is Nothing)
            Wait (200)
        Wend
    
        view.Focus
      
        'Get a handle to the Screen object and navigate to the screen we
        'want to enter the data on
        Set screen = terminal.screen
      
        rCode = screen.WaitForHostSettle(2000, 1000)
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
          
        rCode = screen.WaitForHostSettle(2000, 1000)
        rCode = screen.SendKeys("ISPF")
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
      
        rCode = screen.WaitForHostSettle(2000, 1000)
        rCode = screen.SendKeys("2")
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
      
        rCode = screen.WaitForHostSettle(2000, 1000)
       
        'Put the text into a field in the new session
        rCode = screen.PutText2(projectName, 5, 18)
       
    End Sub     
    
                   

    To run this sample

    1. In a new VT terminal session, enter "demo:UNIX.sim" in the Host Name / IP address field and then enter any crendentials to log on to the session.
    2. In the Visual Basic Editor, insert a module in the project folder and then copy the code into the module code pane.
    3. Select the Project folder and then add a reference to the Attachmate_Reflection_Objects_Emulation_IbmHosts library. 
    4. Copy the code into the module code pane and run the macro. 
    Copy text from one session to another
    Copy Code
    Sub CopyDataBetweenSessions()
       
        Dim rCode As ReturnCode
        Dim projectName As String
      
        'Objects required to open a new session
        Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
        Dim view As Attachmate_Reflection_Objects.view
        Dim screen As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmScreen
        Dim terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
      
        'Get the text to copy from the current session
        projectName = ThisScreen.GetText(2, 28, 3)
      
        'Get a handle to the existing application object (the workspace)
        Set app = GetObject("InfoConnect Workspace")
      
        'Create a new session and the view used to display the session
        Set terminal = app.CreateControl2("{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}")
        terminal.HostAddress = "demo:ibm3270.sim"
      
        Set view = ThisFrame.CreateView(terminal)
        view.Focus
      
        'Get a handle to the Screen object and navigate to the screen we
        'want to enter the data on
        Set screen = terminal.screen
      
        rCode = screen.WaitForHostSettle(2000, 1000)
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
          
        rCode = screen.WaitForHostSettle(2000, 1000)
        rCode = screen.SendKeys("ISPF")
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
      
        rCode = screen.WaitForHostSettle(2000, 1000)
        rCode = screen.SendKeys("2")
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
      
        rCode = screen.WaitForHostSettle(2000, 1000)
       
        'Put the text into a field in the new session
        rCode = screen.PutText2(projectName, 5, 18)
       
    End Sub
    
                   

    Concepts

    This sample uses the GetText method to get the screen text from the current session.

    Then it creates a session as discussed in Dynamically Open a Session.

    After creating the new session, it uses the WaitForHostSettle, SendKeys, and SendControlKey methods to navigate through several screens in the new session to the screen with the Project field.

    For IBM sessions, another approach for this navigation is to handle the NewScreenReady event for the new session as explained in Navigating Sessions.

     

    Finally, it uses the PutText2 method to put the text into field at the specified row and column for the new session. 

     

     

    See Also