How to add toolbar and Ribbon buttons to legacy-VBA with Reflection Desktop 16.2

  • 7024461
  • 28-Feb-2020
  • 23-Jul-2020

Environment

Reflection Desktop (including Pro, for X, for IBM, or for UNIX and OpenVMS) 16.2 or higher

Situation

The legacy-VBA included with Reflection Desktop does not allow the direct addition of buttons to a Host session toolbar, like was possible in Reflection 14.  This technical article describes how to add Ribbon buttons to Reflection Desktop 16.2 using legacy-VBA code.

Resolution

Background

Reflection Desktop 16 does not allow the creation of buttons on a toolbar or Ribbon in the legacy-VBA interface, like Reflection 14 and earlier versions supported.  But there are other methods of adding buttons to the Ribbon in the Reflection Desktop session which can be used with legacy-Reflection VBA.  The user and VBA code are unable to add buttons at run-time; the buttons have to be created in advance and saved on the Ribbon or a Toolbar, where the VBA code can hide or display the button controls as they are needed. 

How to add buttons in legacy-VBA with Reflection Desktop 16.2:

Note: The following example is written for IBM host sessions but this same sort of procedure will also work for UNIX and OpenVMS sessions, by substituting a R2W file for the RSF file, and a RDOX file for the RD3X file.

1. Open an existing RSF host session file from Reflection 14 in Reflection Desktop 16.2.

2. Save this RSF session file in the new Reflection Desktop 16.2 format as an RD3X file.

3. In the Reflection Desktop Host session, go to the ‘Appearance” tab and select the UI Designer.

4. Select the Tab where you wish to place the Buttons from the list of Session / Appearance / Tools / Macro.
    These instructions will place the Buttons on the Session Tab.

5. Select the “Session” tab so it is highlighted in white.

6. Under Insert Controls select “Group” and click on the icon.
    This will add a new chunk to the Ribbon on the right side.
    Note the name of this chuck in the Identifier field.  For example it could be called “chunk2”.
    Set the appropriate Label for this Group.

7. Make sure to click inside the new Group on the ribbon before proceeding.

8. Under Insert Controls select “Button” and click on the icon.
    Notice a new Button is added to the Group.
    Note the name of this button in the Identifier field.  For example it could be called “button3”.

9. For this new Button control, select the “Select Action” button.

10. From the list of actions select “Run embedded Legacy Reflection Macro” .

11. In the Action parameters choose the “Select macro” and choose the legacy macro you wish to run from this Button.
      Set the appropriate Label and Tooltip for this Button, and an icon if desired.
      Uncheck the box which sets the button to be Visible.

Adding the buttons one-after-another in sequence will allow the auto-numbering to be in sequence and make it much easier to work with the buttons from the VBA code.

12. Add Additional buttons as needed by doing the following:

            a. Under Insert Controls select “Button” and click on it to add an additional Button.
                 Notice a new Button is added to the Group.
                 Note the name of this button in the Identifier field.  For example it could be called “button4”.

            b. For this new Button control, select the “Select Action” button.

            c. From the list of actions select “Run embedded Legacy Reflection Macro”.

            d. In the Action parameters choose the “Select macro” and choose the legacy macro you wish to run from this Button.
                Set the appropriate Label and Tooltip for this Button, and an icon if desired.
                Uncheck the box which sets the button to be Visible.

13. Press the OK button at the bottom of the dialog to save the newly created Ribbon File.
      A dialog which says the following will appear:
              “A custom version of the current built-in file already exists”
              “Please provide a filename for the new file.”

14. Press OK.

15. Save the new Ribbon file as an *.XUML file in the “C:\Users\<username>\Documents\Micro Focus\Reflection\CustomUI folder.
      For example call it:   Reflection2007.3270.Ribbon.NewButtons.xuml

16. Make sure to save the Reflection Host session file (RD3X file) so that the newly created Ribbon will be associated with this host session.
      Notice at this point in time there will be a new Group added to the Ribbon on the Session tab, but it will be blank. 
      This is because the Buttons are not set as visible.  We will make the buttons visible when the VBA code runs.

17. Next create VBA code to show/hide/disable/enable the various Button controls using the Identifiers you recorded above.
      For this example the Group was called “chunk2” and the Buttons are called “button3” and “button4”.

18. Open the VBA Editor under the Macro tab in the Reflection Desktop host session.

19. Find the modules which contain the existing DefineToolbarButton() methods.
      This code will be replaced by something like the following:

      Place the following code at the beginning of the Sub()
      ' Get the new Reflection Desktop Ribbon objects in the new VBA
      Dim ui As UiMode
      Dim control As UiControl
      Dim screenID As String
      Set ui = ThisView.UiMode
      ui.Reset

     Place this code in the Sub() to replace the existing button code
     ' Make the Ribbon Chunk visible
     Set control = ui.GetControlById("chunk2")   ‘ note the name of the Group added to the Ribbon earlier
     control.Visible = True
     control.Enabled = True
   
     ' Set the state on the various button controls to be visible
     Set control = ui.GetControlById("button3")   ‘ note the name of the button added to the Ribbon earlier
     control.Visible = True
     control.Enabled = True
     Set control = ui.GetControlById("button4")    ‘ note the name of the button added to the Ribbon earlier
     control.Visible = True
     control.Enabled = True
              
        OR

     ' Make the Ribbon Chunk invisible
     Set control = ui.GetControlById("chunk2")
     control.Visible = False
     control.Enabled = False

     ' Set the state on the various button controls to be invisible
     Set control = ui.GetControlById("button3")
     control.Visible = False
     control.Enabled = False
     Set control = ui.GetControlById("button4")
     control.Visible = False
     control.Enabled = False

Limitations:

There are some limitations to the preceding VBA code:

        1. It will only work with Reflection Desktop 16.2 and higher versions.

        2. It will only work reliably when running one Reflection host session at a time.
            (unless some additional VBA Project naming configuration is done, which is beyond the scope of this article)

Feedback service temporarily unavailable. For content questions or problems, please contact Support.