Create a Macro to Save Host Screen Data to a File

  • 7021515
  • 16-Jan-2009
  • 11-Sep-2018

Environment

Reflection Desktop 16.0 and later
Reflection 2014
Reflection for IBM 2014
Reflection for UNIX and OpenVMS 2014
Reflection for IBM 2011
Reflection for UNIX and OpenVMS 2011
Reflection Standard Suite 2011

Situation

Follow the steps in this technical note to create a macro that enables you to save the host data on your screen to a text file.

Resolution

To enable users to save the current screen contents to a text file, create and insert a VBA macro in your session settings file. (In EXTRA!, this option is available from the File menu.)
  1. Open a session document.
  2. Click the Tools tab. In the Macro group, click Visual Basic to open the editor.
  3. In the left Project pane, right-click Project, and click Insert > Module.
  4. Copy the following code and paste it into the new module. The code you copy and paste depends on the session type you are using.

For IBM (3270 or 5250) sessions:

Sub PrintScreenToFile()
    Dim sText As String
    Dim sFilename As String
    Dim i As Integer
    Dim rows As Integer
    Dim cols As Integer
    rows = ThisIbmScreen.rows
    cols = ThisIbmScreen.columns

    If ThisIbmTerminal.IsConnected = False Then
       MsgBox "Not Connected...", , "PrintScreenToFile"
       Exit Sub
    End If

    'collect screen data....
    For i = 1 To rows
       sText = sText & ThisIbmScreen.GetText(i, 1, cols) & vbCrLf
    Next

    'determine where "My Documents" is located, and prompt for filename
    sFilename = Environ("USERPROFILE") & "\Documents\HostScreen.txt"
    sFilename = InputBox("Save screen data to what file?", "PrintScreenToFile", sFilename)

    'if they didn't choose "cancel", write the file out
    If sFilename <> "" Then
       On Error GoTo handler
       Open sFilename For Output As #1
       Print #1, sText
       Close #1
    End If

    Exit Sub

handler:
    MsgBox Err.Description
    Reset
End Sub

For UNIX or OpenVMS sessions:

Sub PrintScreenToFile()
   Dim sText As String
   Dim sFilename As String
   Dim sUserProfile As String
   Dim i As Integer
   Dim rows As Integer
   Dim cols As Integer
   rows = ThisScreen.DisplayRows
   cols = ThisScreen.DisplayColumns

   'collect screen data....
   For i = 1 To rows
      sText = sText & ThisScreen.GetText(i, 1, cols) & vbCrLf
   Next

   'determine where "My Documents" is located, and prompt for filename
   sUserProfile = Environ("USERPROFILE")
   sFilename = sUserProfile & "\Documents\HostScreen.txt"
   sFilename = InputBox("Save screen data to what file?", "Save", sFilename)

   'if they didn't choose "cancel", write the file out
   If sFilename <> "" Then
      On Error GoTo handler
      Open sFilename For Output As #1
      Print #1, sText
      Close #1
   End If

   Exit Sub

   handler:
   MsgBox Err.Description
   Reset

End Sub
  1. Click File > Save to save the module to your session settings file.

Saving the Host Screen Data

To save the host data on the screen to a text file, run the macro that you added to the settings file.

  1. Click the Tools tab. In the Macro group, click Run Macro.
  2. In the Run Macro dialog box, click "Reflection Workspace Macro" as the type of macro.
  3. In the Macros dialog box, select Module1.PrintScreenToFile and click Run.
  4. In the PrintScreenToFile dialog box, enter the path and file name to save the screen data and click OK. (By default, the text file is named HostScreen.txt and is saved to your My Documents folder.)

Additional Information

Legacy KB ID

This document was originally published as Attachmate Technical Note 2410.