How to Google any text in the terminal display

  • 7023305
  • 24-Aug-2018
  • 27-Aug-2018

Environment

Reflection Desktop 16.0 or later
InfoConnect Desktop 16.0 or later

Situation

Thanks to the Reflection (and InfoConnect) web browser feature, it is easy to use a VBA macro to get selected text on the terminal screen and use that for a  Google query, displaying the results right there in the Reflection Workspace.

This example demonstrates Google queries, but the same concept could be extended to any web resource that allows search terms to be included in the URL.

Resolution

  1. Create and save a new Reflection mainframe or iSeries session (*.rd3x or *.rd5x).
  2. Connect the session to your host system.
  3. Open the Reflection Visual Basic Editor (...on the ribbon's "Macros" tab).
  4. In the "new" project (not the "legacy" project), insert a new VBA module.
  5. Copy the Visual Basic code below to the new module. Save.
  6. For convenience, edit the Reflection context menu to add an action that runs this macro.
  7. Note: This example can easily be adapted for use with a Unix or Unisys session.
  8. Note: This example won't work if Reflection's "Web Browser" feature has not been installed.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' GoogleSelection
'
' This macro will take the text currently selected in the terminal and do a
' Google query on it, opening a new web browser tab to display the results
' in the Reflection Workspace. For convenience, configure Reflection's
' context menu (right-click menu) to run this.
'
' Example code provided without warranty or support.
' Please review and understand it before running.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub GoogleSelection()
    Const WebControlGUID = "{F1F058B1-0472-4095-A782-3D7333813AD0}"
   
    Dim region As ScreenRegion
    Set region = ThisIbmScreen.Selection
   
    If region.StartRow = 0 Then
        MsgBox "No selection."
        Exit Sub
    End If
   
    'Get the text currently selected on the screen.
    Dim searchText As String
    searchText = ThisIbmScreen.GetTextEx(region.StartRow, _
                                         region.StartColumn, _
                                         region.EndRow, _
                                         region.EndColumn, _
                                         GetTextArea.GetTextArea_Block, _
                                         GetTextWrap_Off, _
                                         GetTextAttr_Any, _
                                         GetTextFlags_None)
    Dim webctrl As WebControl
    Dim newview As View
   
    'Create a new Reflection WebControl, based on GUID value (see help).
    'Then create a new Reflection View to host the new WebControl.
    Set webctrl = Application.CreateControl2(WebControlGUID)
    Set newview = ThisFrame.CreateView(webctrl)
           
    webctrl.Navigate1 "https://www.google.com/search?q=" & searchText
  
    'When closing the WebControl tab, there will be a prompt to save
    'the new .urlx document just created. If you want to avoid making people
    'click on that, save the .urlx for them. Note: only URL information
    'is saved to the .urlx document, not the HTML content written.
    Dim rc As ReturnCode
    rc = webctrl.SaveAs(Environ("USERPROFILE") & "\documents\Micro Focus\Reflection\url.urlx")
    If rc <> ReturnCode_Success Then
        MsgBox "urlx SaveAs error!"
    End If
    'Set the title on the new View (tab).
    newview.titleText = "Google"
    webctrl.Save
End Sub

Additional Information

Using the Context Menu Editor to add a menu item to run the GoogleSelection macro:

Now select some text you want to know more about, and right-click...

Google's results...