Quick Start > Create a Macro with the VBA Editor |
This example shows how to create a macro that gets text from the screen and displays it in a message box.
![]() |
This article contains tabbed content that is specific to each terminal type. Be sure the tab for your terminal type is selected. |
![]() |
The name you choose for the subroutine must follow the Visual Basic naming conventions for macros. For more information, see Naming Macros. |
Get text from the screen |
Copy Code
|
---|---|
Sub CopyTextMacro() 'Create a variable to hold the text Dim screenText As String 'Get text from the screen starting at screen row 1, column 1, and 30 characters long screenText = ThisIbmScreen.GetText(1, 1, 30) 'Display the text in a message box MsgBox (screenText ) End Sub |
Get text from the screen |
Copy Code
|
---|---|
Sub CopyTextMacro() 'Create a variable to hold the text Dim screenText As String 'Get text from the screen starting at screeen column 1, row 1 ' and ending at row 30, column 30 screenText = ThisScreen.GetText2(1, 1, 30, 30) 'Display the text in a message box MsgBox (screenText ) End Sub |
For information about editing legacy Reflection Basic or EXTRA! macros, see Using Legacy Macros.
This macro uses an InfoConnect property (ThisScreen for Open Systems or ThisIbmScreen for IBM) to get the screen object for the session. You can use this property to get the screen object for any macro in a session project. InfoConnect provides several other properties that you can use to get key objects when you are creating macros in session projects. For more about these properties, see Using the InfoConnect Object Model.
The screen object represents the host application screen and it provides methods and properties used to access host screen data. The GetText method used in the IBM sample is used to get the text from a screen location. The Open Systems library also has a GetText method that you can use in the same way.
![]() |
The GetText2 method used in the Open Systems sample is used to get the text in a region of the screen. The IBM library GetTextEx method can be used for the same purpose. |