InfoConnect 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 it creates another demo session, navigates to a screen on the new session, and puts the text into a field on that session.

    If you prefer to run macros in pre-configured sessions instead of creating your own sessions, you can download the VBA Sample Sessions and open the copy-data-between-terminal-sessions.rd5x  (IBM) and the copy-data-between-terminal-sessions.rdox (Open Systems) files. The download package contains everything you need to run the macros in these files. See Download the VBA Sample Sessions.

    The following samples apply to IBM and Open Systems sessions.

    This article contains tabbed content that is specific to each terminal type. Be sure the tab for your Which Terminal Type are you Using? is selected.

    This example creates an IBM 3270 session and copies the Kayak text from the 5250 session to the new session.  

    Note: This example macro uses the WaitForHostSettle method to wait until the screen is ready for input. To get the best performance for macros that navigate screens, consider using a SmartWait method as shown in Navigating Through IBM Screens.

    To run this sample

    1. Create a new Ibm 5250 terminal session, and enter "demo:ibm5250.sim" in the Host name/IP address field.
    2. When the session "Sign On" screen opens, press Enter to navigate to the next screen.
    3. On the "AS/400 Main Menu" screen,  Enter "kayak" to go the next screen.
      The INTERNATIONAL KAYAK ENTERPRISES screen has the data to copy.
    4. In the Visual Basic Editor, insert a module in the project folder, copy the following code into the module code pane, and press F5 to 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     
    
                   

    This example creates an IBM 3270 session and copies the XYZ text from the existing session to the new session.

     

    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 credentials to log on to the session.
    2. On the demo> prompt on the second screen, enter "demodata".
    3. In the Visual Basic Editor, insert a module in the project folder and then copy the code into the module code pane.
    4. Select the new module in the Project folder.
    5. From the Visual Basic Editor Tools menu, choose References and then add a reference to the Attachmate_Reflection_Objects_Emulation_IbmHosts library. 
    6. 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.

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

     

     

    See Also