InfoConnect VBA Guide
Quickstart / Dynamically Create a Session
In This Topic
    Dynamically Create a Session
    In This Topic

    You can create a session from an InfoConnect macro. This example shows how to create a macro in an InfoConnect project. Macros in the Common project can be run from any session or from the workspace. 

    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 dynamically-create-a-session.rd3x (IBM) and dynamically-create-a-session.rdox (Open Systems) files. For the Open Systems sample, be sure to change the placeholder on the line of code that specifies the HostAddress to your host name or IP address. The download package contains everything you need to run the macros in these files. See Download the VBA Sample Sessions.

    Create an InfoConnect session                        

    1. Create or open a new InfoConnect session.
    2. On the Tools tab, select Visual Basic to open the Visual Basic Editor.
    3. In the Visual Basic Project Explorer, right click on the project folder, and choose Insert > Module.
    4. If the session you want to open is not the same terminal type as your existing session, add a reference to the session terminal type. For example, if you are running an Open Systems terminal session and you want to open an IBM terminal session document, you'll need to add a reference to the Attachmate_Reflection_Objects_Emulation_IbmHosts library. To do this, select your project folder in the Project window. Then select Tools > References on the Visual Basic Editor menu and select the library.
    5. If you are using an ALC, UTS, or T27 terminal, create a session path. This sample uses the following path IDs:
      ALC: UPDFRAD
      UTS: INT1_1
      T27: TCPA_1
    6. Add the following code into the new module's code window.
      Create an InfoConnect IBM Session
      Copy Code
                                          
      Sub CreateInfoConnectIBMSession()
          'Declare application, terminal, and view object variables:
          Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
          Dim terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
          Dim view As Attachmate_Reflection_Objects.view
           
          'Get a handle to the workspace
          Set app = GetObject("InfoConnect Workspace")
                       
          'Create an Ibm3270 control and set the host address
          Set terminal = app.CreateControl2("{09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}")
          terminal.HostAddress = "demo:ibm3270.sim"
          terminal.port = "623"
         
          'For an Ibm5250 control, use the following Guid:
          'Set terminal = app.CreateControl2("{AF03A446-F278-4624-B9EF-C896DF2CA1CA}" )
         
          'Create a view to display the session
          Set view = ThisFrame.CreateView(terminal)
         
      End Sub
         
      
      Create an InfoConnect Open Systems Session
      Copy Code
      Sub CreateInfoConnectOpenSystemsSession()
          'Declare application, terminal, and view object variables:
          Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
          Dim terminal As Attachmate_Reflection_Objects_Emulation_OpenSystems.Terminal
          Dim view As Attachmate_Reflection_Objects.View
           
          'Get a handle to the workspace
          Set app = GetObject("InfoConnect Workspace")
                       
          'Create an Open Systems control and set the host address
          Set terminal = app.CreateControl2("{BE835A80-CAB2-40d2-AFC0-6848E486BF58}")
          terminal.ConnectionSettingsTelnet.HostAddress = "yourHostName"
         
          'Create a view to display the session
          Set view = ThisFrame.CreateView(terminal)
         
      End Sub
      
      Create a session
      Copy Code
      Sub CreateALCSession()
          'Declare application, terminal, and view object variables:
          Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
          Dim terminal As Attachmate_Reflection_Objects_Emulation_ALC.AlcTerminal
          Dim View As Attachmate_Reflection_Objects.View
           
          'Get a handle to the workspace
          Set app = GetObject("InfoConnect Workspace")
                         
          'Create a control and set the path
          Set terminal = app.CreateControl2("{0327C7A7-820D-4F9F-8BD6-11E0398605F1}")
          terminal.PathId = "UPDFRAD"
         
         
          'Create a view to display the session
          Set View = ThisFrame.CreateView(terminal)
         
      End Sub
      
      Create a session
      Copy Code
      Sub CreateUTSSession()
          'Declare application, terminal, and view object variables:
          Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
          Dim terminal As Attachmate_Reflection_Objects_Emulation_UTS.UtsTerminal
          Dim View As Attachmate_Reflection_Objects.View
           
          'Get a handle to the workspace
          Set app = GetObject("InfoConnect Workspace")
                         
          'Create a control and set the path
          Set terminal = app.CreateControl2("{C8ADCD4F-3DF8-4BCA-821B-995FEF8DAFEF}")
          terminal.PathId = "INT1_1"
         
         
          'Create a view to display the session
          Set View = ThisFrame.CreateView(terminal)
         
      End Sub
      
      Create a session
      Copy Code
      Sub CreateT27Session()
          'Declare application, terminal, and view object variables:
          Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
          Dim terminal As Attachmate_Reflection_Objects_Emulation_T27.T27Terminal
          Dim View As Attachmate_Reflection_Objects.View
           
          'Get a handle to the workspace
          Set app = GetObject("InfoConnect Workspace")
                         
          'Create a control and set the path
          Set terminal = app.CreateControl2("{2AB85541-5BE6-4BCB-8AF5-DA2848DBA28C}")
          terminal.PathId = "TCPA_1"
         
         
          'Create a view to display the session
          Set View = ThisFrame.CreateView(terminal)
         
      End Sub
      
    7. If you are using the Open Systems sample, change the placeholder on the line of code that specifies the HostAddress to your host name or IP address.
    8. Place the cursor in the code window and then press F5 to run the macro.

    Concepts

    To create a session from another application, you'll need to use the InfoConnect ApplicationObject, Frame, View, and terminal objects.

    For more about these objects, see Using the InfoConnect Object Model.

    This sample uses the CreateControl2 method to create the terminal control for the session. This method returns the appropriate terminal control for the GUID value that you pass to it. Each type of terminal supported by InfoConnect has a unique GUID, as shown below:

    Terminal Control GUID
    Ibm 3270 {09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1}
    Ibm 5250 {AF03A446-F278-4624-B9EF-C896DF2CA1CA} 
    VT (Open Systems) {BE835A80-CAB2-40d2-AFC0-6848E486BF58}
    Web {F1F058B1-0472-4095-A782-3D7333813AD0}
    ALC {0327C7A7-820D-4F9F-8BD6-11E0398605F1}
    UTS {C8ADCD4F-3DF8-4BCA-821B-995FEF8DAFEF}
    T27 {2AB85541-5BE6-4BCB-8AF5-DA2848DBA28C}

     

    We use the terminal control to set the host address. For IBM sessions, you can also use it to set the port.

    terminal.HostAddress = "demo:ibm3270.sim"
    terminal.Port = "623"
    

    For Open Systems sessions, you will need to set the type of connection you want to use first. InfoConnect supports a number of connection types, including Telnet and Secure Shell (SSH).

    'Create a Telnet connection and set the host name to connect to
    terminal.ConnectionSettingsTelnet.HostAddress = "yourHostName"
    

    You can also create this macro in a Common project module and then call it to create this session. Macros in the Common project can be called by any session or by workspace actions. For more about this, see Sharing and Referencing Macros and Controlling Macro Execution.


     

    See Also