Show Contents / Index / Search

Programming Exercise

This exercise demonstrates how to create a macro that uses Reflection methods to get text from the screen display and copy it to the Clipboard. As you type the code, you can observe some of the Visual Basic Editor features that help simplify this process.

To create the ClipboardDemo macro

  1. Open a Reflection 2008 session document, and connect to a host.
  2. On the Tools tab, click Visual Basic.

    The Visual Basic Editor opens.

  3. In the Project Explorer, select the session document (project), and choose Insert > Module.
  4. Double-click the new module.

    The Code window opens.

  5. Choose Insert > Procedure, and then, in the Name box, type ClipboardDemo, and click OK.
  6. With the insertion point between the Public Sub and End Sub lines, type one of the following lines:
    • IBM hosts: Call ThisIbmScreen
    • OpenSystems hosts: Call ThisScreen

    This calls the Screen object, which controls onscreen characters and text.

  7. Set the position on the screen from which the macro selects text using the SetSelectionStartPos method. For 3270 and 5250 sessions, the line should appear as follows:

    Call ThisIbmScreen.SetSelectionStartPos(1,1)

    Note: When you type the period (.) after the Screen object, a context menu appears. If you type the letter "s", the menu shows all items that start with "s".

  8. Define the total selection area using the ExtendSelection method to set the end position of the text selection at row 5, column 80.

    Using the IBM example, this line should appear as follows:

    This.IbmScreen.ExtendSelection.Type (5, 80)

  9. Type the following line to copy the selected text to the Clipboard:
    • IBM hosts: Call ThisIbmScreen.Copy
    • OpenSystems hosts: Call ThisScreen.Copy
  10. Send a notification when the task has been completed using the MsgBox statement:

    MsgBox "Screen text has been copied to the Clipboard."

The Immediate window in the Visual Basic Editor is a debugging tool that you can use to test code. In the following exercise, you use it as a scratch pad to paste the Clipboard contents.

To test the macro

  1. Select View > Immediate Window.
  2. Place the insertion point anywhere in the ClipboardDemo procedure you just created.
  3. Run the procedure from the Visual Basic Editor using one of the following techniques:
    • Select Run > Run Sub/UserForm.
    • Press F5.
    • From the Visual Basic toolbar, click the Run button.
  4. Click the Immediate window and press Control+V to paste the text that was copied from your host screen to the Clipboard.
  5. In the Visual Basic Editor or Reflection 2008, select File > Save.

    This saves your macro. Otherwise, your macro is not saved until you save your settings file.

    Your ClipboardDemo code should look like one of the following examples.

    • IBM hosts:

      Public sub ClipboardDemo()
      Call ThisIbmScreen.SetSelectionStartPos(1,1)
      Call ThisIbmScreen.ExtendSelection(5,80)

      Call ThisIbmScreen.Copy
      MsgBox "Screen text has been copied to the Clipboard."
      End Sub

    • OpenSystems hosts:

      Public sub ClipboardDemo()
      Call ThisScreen.SetSelectionStartPos(1,1)
      Call ThisScreen.ExtendSelection(5,80)

      Call ThisScreen.Copy
      MsgBox "Screen text has been copied to the Clipboard."
      End Sub