Reflection Desktop VBA Guide
HowTos / Save Screens as Text
Save Screens as Text

This sample saves the text displayed  in a terminal session to a text file.

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 save-screens-as-text.rd3x (IBM) and log-os-screen-data.rdox files. The download package contains everything you need to run the macros in these files. See Download the VBA Sample 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 sample gets all of the text on a screen before the screen data is transmitted and saves it to a text file.

To run this sample

  1. In an Ibm terminal session, open the Visual Basic Editor, copy the code into the ThisIbmScreen code window.
  2. Save the session and then reopen it.
  3. Enter some data on a terminal session screen and then open the log file to check the results. (The .log file has the same name as your session document file and is in the same folder as that file.)
    Save screens as text
    Copy Code
     Private Function IbmScreen_BeforeSendControlKey(ByVal sender As Variant, key As Long) As Boolean
        Dim screenRows As Integer
        Dim screenColumns As Integer
        Dim fnum As Integer
        Dim screenShot As String
        screenRows = ThisIbmScreen.rows
        screenColumns = ThisIbmScreen.columns
       
        'Get all the text on the screen
        screenShot = ThisIbmScreen.GetTextEx(1, 1, screenRows, screenColumns, GetTextArea_Block,  _
        GetTextWrap_Off, GetTextAttr_Any, GetTextFlags_CRLF)
       
        'Add a line to separate each screen
        screenShot = screenShot & "................................................................................"
       
        'Open a file and append the screenshot to the file
        path = ThisIbmTerminal.SessionFilePath & ".log"
        fnum = FreeFile()    
        Open path For Append As fnum
        Print #fnum, screenShot
        Close #fnum
       
        IbmScreen_BeforeSendControlKey = True
    End Function
    

Concepts

This sample handles the BeforeSendControlKey event to append all the text on the screen to a log file before leaving the screen. The GetTextEx method is used to capture a region of a screen and in this case, arguments are passed to capture the whole screen from position 1,1 to the maximum rows and columns.

A line is added to the data to separate the screens before the data is appended to a file.

For more about ways you can use events, see Using Reflection Events.

 

 

See Also