VBA: Reflection Desktop

Xlacs

Board Regular
Joined
Mar 31, 2021
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hi Good People,

Below code opens a session of reflection desktop and extract data from a particular screen.
My problem is, I don't want to open another session, instead it should find the active session of reflection workspace then execute the code. However,
I am nowhere near from that the goal.

Humbly asking from your assistance. Thank you!!

VBA Code:
Public WithEvents screen As Attachmate_Reflection_Objects_Emulation_IbmHosts.ibmScreen
Public Sub GetDataFromIBMScreen()
    'Declare an object variable for the Reflection object
    Dim app As Attachmate_Reflection_Objects_Framework.ApplicationObject
   
    'Declare additional Reflection objects, such as frame, terminal, and view
    Dim frame As Attachmate_Reflection_Objects.frame
    Dim terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
    Dim view As Attachmate_Reflection_Objects.view
   
    'Create a new instance of Reflection
    Set app = New Attachmate_Reflection_Objects_Framework.ApplicationObject
 
    'wait until Reflection initializes
    Do While app.IsInitialized = False
        app.Wait (200)
    Loop
 
    'Create controls to open and display the session document.
    Set frame = app.GetObject("Frame")
    frame.Visible = True
   
    Set terminal = app.CreateControl2("09E5A1B4-0BA6-4546-A27D-FE4762B7ACE1")
                          
    terminal.HostAddress = "demo:ibm3270.sim"
    Set view = frame.CreateView(terminal)
    Set screen = terminal.screen
End Sub
Private Sub screen_NewScreenReady(ByVal sender As Variant)
    'In this IbmScreen
 
    Dim screenID1 As String, screenID2 As String, screenID3 As String
    Dim rCode As ReturnCode
    Dim rowText As String
    Dim rowFromHost() As String
    Dim col As Integer, row As Integer
 
    screenID1 = screen.GetText(1, 2, 6) 'ATM VM ispf
    screenID2 = screen.GetText(1, 7, 4) 'option 2
    screenID3 = screen.GetText(1, 25, 13) 'option 2
    
    If screenID1 = "ATM VM" Then
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
    End If
 
    If screenID2 = "ATM5" Then
        rCode = screen.PutText2("kayak", 23, 1)
        rCode = screen.SendControlKey(ControlKeyCode_Transmit)
    End If
 
    If screenID3 = "INTERNATIONAL" Then
     
        'Start on row 7 and get the first row of text from the screen
        row = 7
        rowText = screen.GetText(row, 9, 65)
        'Gather data until an empty row is encountered
        Do
            'Replace spaces between compound words in first column and remove extra spaces
            rowText = Replace(rowText, " ", "_", 1, 1)
            rowText = Application.WorksheetFunction.Trim(rowText)
         
            'Place each column into an array
            rowFromHost = Split(rowText, " ")
         
            For col = LBound(rowFromHost) To UBound(rowFromHost)
                'Replace delimiter that was added for compound words
                rowFromHost(col) = Replace(rowFromHost(col), "_", " ", 1, 1)
                'Write each column in the row to the spreadsheet
                Cells(row, (col + 5)).Value = rowFromHost(col)
            Next col
         
            row = row + 1
         
            'Get the new row of text from the screen
            rowText = screen.GetText(row, 9, 65)
          
            Debug.Print row
      
        'Check string length after removing all extra spaces
        Loop While Len(Application.WorksheetFunction.Trim(rowText)) > 0
     
    End If
     
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top