Reflection Desktop VBA Guide
Quickstart / Dynamically Open a Session
In This Topic
    Dynamically Open a Session
    In This Topic

    You can open or close sessions dynamically. This example shows how to open a terminal session from another session that is running in the Reflection workspace.

    Create the Session Document you Want to Open

    1. Open Reflection and create the session you want to open.
    2. Save the session in a trusted location. For this example, we saved a session named "gettingStarted" in the Documents/Micro Focus/Reflection folder.
    You can open only sessions that are saved in trusted locations (Documents/Micro Focus/Reflection is a default trusted location). For information about trusted locations and how to add them, see the Reflection Help.

    Create a Macro to open the Session      

    1. Create or open a new Reflection 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 and select the library.
    1. Copy the following code into the module and press F5 to run it.  
      Open a session document from Reflection
      Copy Code
      Sub OpenSessionDocument()     ' Objects required to open a new session
          Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
          Dim terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
          Dim view As Attachmate_Reflection_Objects.View
       
          Dim sessionPath As String      
       
          'Get a handle to the existing application object (the workspace)
          Set app = GetObject("Reflection Workspace")
       
          'Create a terminal control for the new session
          sessionPath = Environ$("USERPROFILE") & "\Documents\Micro Focus\Reflection\" & "gettingStarted.rd3x"
          Set terminal = app.CreateControl(sessionPath)
       
          'Create the view used to display the session
          Set view = ThisFrame.CreateView(terminal)
      End Sub
      
      Open a session document from Reflection
      Copy Code
      Sub OpenSessionDocument()    
          'Objects required to open a new session
          Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
          Dim terminal As Attachmate_Reflection_Objects_Emulation_OpenSystems.Terminal
          Dim view As Attachmate_Reflection_Objects.View
          Dim sessionPath As String
      
          'Get a handle to the existing application object (the workspace)
          Set app = GetObject("Reflection Workspace")
         
          'Create a terminal control for the new session
          sessionPath = Environ$("USERPROFILE") & "\Documents\Micro Focus\Reflection\" & "gettingStarted.rdox"
          Set terminal = app.CreateControl(sessionPath)
       
          'Create the view used to display the session
          Set view = ThisFrame.CreateView(terminal)
      End Sub
      
                   

    Concepts

    To open a session, you'll need access to the Application, IbmTerminal (IBM) or Terminal (Open Systems), and View objects:

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

    You can also create this macro in a Common project module and then call it to open 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