To develop solutions that use the Reflection VBA, you'll need to interact with the objects provided by the Reflection object model. This topic introduces the most important objects:
Terminal and Web Control Objects
Conceptually, the Application object represents the Reflection application. It is the top root object from which you can get various parts of the object model. The Application object is not visible within a project (that is, it doesn't appear in the Project Explorer pane in Visual Basic for Applications).
In Reflection macros, you'll need to access this top level object to programmatically create sessions, find out how many sessions are running, or access other running sessions.
Getting a handle to Reflection |
Copy Code
|
---|---|
Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject Set app = GetObject("Reflection Workspace") |
From another application, you can use an existing instance of Reflection if it is running or open an instance if it is not:
Creating a new instance of Reflection |
Copy Code
|
---|---|
Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject On Error Resume Next 'Try to use the existing workspace Set app = GetObject("Reflection Workspace") On Error GoTo 0 'Otherwise, create new instance of Reflection If IsEmpty(app) Or (app Is Nothing) Then Set app = New Attachmate_Reflection_Objects_Framework.ApplicationObject End If |
To work with host sessions, you use Terminal and Screen objects. Together with their child objects, the Terminal and Screen objects make up all of the functionality within a host session. For Reflection Web sessions, you'll use the WebControl object to access the session objects.
Two high level objects are required to display Reflection sessions:
To display a session, you'll need to get the Frame object, Create a View object, and associate the Terminal object with the View object.
Displaying a session |
Copy Code
|
---|---|
Dim Frame As Attachmate_Reflection_Objects.Frame Dim view As Attachmate_Reflection_Objects.view 'Create controls to open and display the session document. Set Frame = app.GetObject("Frame") 'Make Frame visible to display the workspace Frame.Visible = True 'Create a view for the terminal to display the session Set view = frame.CreateView(terminal) |
You can also access the Frame object with the ThisFrame property. If you're programming in a Reflection project module, you can use the ThisView property to access the view for the session.
Getting the Frame and View objects in a project module |
Copy Code
|
---|---|
ThisFrame.Visible=True ThisView.ActiveTabBackgroundColor = RGB(0, 0, 0) ThisView.ActiveTabForegroundColor = RGB(255, 255, 255) ThisView.InactiveTabBackgroundColor = RGB(20, 200, 250) |
You can use Frame object methods to access views and terminal controls of other open sessions.
To identify a particular View object, you can specify it by title, ID, or file path. For example, to write a macro that acts on one of three open session documents, you can get a View object by using the text that appears on the session's tab or by using the path to where its session file is saved. After you have the View object, you can use it to get the terminal control object for that session.
Getting a View and a Terminal control |
Copy Code
|
---|---|
Sub CheckViews() Dim osTerminal As Attachmate_Reflection_Objects_Emulation_OpenSystems.Terminal Dim ibmTerminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.ibmTerminal Dim webCntrl As Attachmate_Reflection_Objects.WebControl Dim sessionName As String Dim views() As Attachmate_Reflection_Objects.View Dim osView As Attachmate_Reflection_Objects.View 'Catch error if sessions are not open On Error GoTo MyHandler 'Get the view and terminal control from the session path and filename sessionName = Environ$("USERPROFILE") & "\Documents\OpenText\Reflection\" & "GetDataFromExcel.rd3x" views = ThisFrame.GetViewsByFilePath(sessionName) Set ibmTerminal = views(0).control 'Get the view and terminal control from the title text on the view's tab sessionName = "osSession.rdox" Set osView = ThisFrame.GetViewByTitleText(sessionName) Set osTerminal = osView.control Exit Sub 'If a session is not open, send a message to open it and then exit MyHandler: MsgBox "You need to open" & sessionName Exit Sub End Sub |
For each legacy document, Reflection creates an additional VBA project for the supported legacy API. This legacy API VBA project includes objects that provide backward compatibility for legacy macros. (You can view the legacy API VBA project in the Project Explorer window of the Visual Basic Editor.) To determine which legacy API is supported, see Using Extra! and Legacy Reflection Macros.