Reflections WRQ VBA

Robertson1995

Board Regular
Joined
Apr 1, 2009
Messages
117
I have the following code that I use in WRQ Reflections. It is very basic and runs the command bts_status mc800bts877. The characters "877" which are in red below is a site # which changes. What I need is for the macro to run the command bts_status mc800bts and then have an inputbox ask for the next 3 characters (in this example 877) that then carriage return after ok is selected on the input box. Thanks.


Sub Macro1()
' Generated by the Reflection Macro Recorder on 04-22-2009 09:01:25.57.
' Generated by Reflection for UNIX and Digital 8.0.6.
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim CR As String ' Chr$(rcCR) = Chr$(13) = Control-M
Dim ESC As String ' Chr$(rcESC) = Chr$(27) = Control-[
CR = Chr$(rcCR)
ESC = Chr$(rcESC)
With Session
.Transmit "bts_status mc800bts877" & CR
' .WaitForString ESC & "[K", NEVER_TIME_OUT, rcAllowKeystrokes
Exit Sub
ErrorHandler:
.MsgBox Err.Description, vbExclamation + vbOKOnly
End With
' Recording stopped at 09:04:44.83.
End Sub
 
let me tell you the complete procedure
1st of reflection is already opened and connected with the Host ip and on the other hand we have Excel
need to run macro in excel so that Reflection can be linked with Excel and
1 step : Transmit f9 key
2 :
.WaitForEvent rcEnterPos, "30", "0", 1, 1
.TransmitTerminalKey rcIBMPf9Key
.WaitForEvent rcKbdEnabled, "30", "0", 1, 1
.WaitForEvent rcEnterPos, "30", "0", 5, 13
.WaitForDisplayString "==>", "30", 5, 9
.TransmitANSI "1"
.TransmitTerminalKey rcIBMEnterKey
.WaitForEvent rcKbdEnabled, "30", "0", 1, 1
.WaitForEvent rcEnterPos, "30", "0", 18, 33
.WaitForDisplayString "ID:", "30", 18, 29
.TransmitANSI "user id"
.TransmitTerminalKey rcIBMTabKey

' Password has not been recorded for security
Dim hostpassword As String
hostpassword = ""
hostpassword = .GetPassword("PASSWORD:", "", "", "")
.TransmitANSI hostpassword
.TransmitANSI "50.7.13"
.TransmitTerminalKey rcIBMEnterKey

And then Get data from excel and paste in REflection
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Let me try to explain what your recorded code does.

.WaitForEvent rcEnterPos, "30", "0", 1, 1Make the client wait a maximum of 30 seconds for the cursor to reach row 1, column 1
.TransmitTerminalKey rcIBMPf9KeyTransmit the F9 button to the client
.WaitForEvent rcKbdEnabled, "30", "0", 1, 1Wait max 30 seconds, for the keyboard to be enabled to the user again. It locks the keyboard while it "thinks"
.WaitForEvent rcEnterPos, "30", "0", 5, 13Wait max 30 sec for cursor to enter pos 5, 13
.WaitForDisplayString "==>", "30", 5, 9Wait max 30 secs for the string "==>" to appear at location 5,9
.TransmitANSI "1"Send the text "1"
.TransmitTerminalKey rcIBMEnterKeyTransmit the ENTER button
.WaitForEvent rcKbdEnabled, "30", "0", 1, 1Wait max 30 secs for the keyboard to be enabled
.WaitForEvent rcEnterPos, "30", "0", 18, 33Wait max 30 secs for the cursor to enter position 18,33
.WaitForDisplayString "ID:", "30", 18, 29Wait max 30 secs for the string "ID:" to appear at location 18,29
.TransmitANSI "user id"Send text "user id" to the client
.TransmitTerminalKey rcIBMTabKeySend TAB key to the client

A lot of these lines of code can be avoided. As you see in my functions, they have build in waiting.

So what you could cook the above down to is

Code:
SendTerminalKey [COLOR=#574123]rcIBMPf9Key 'Send F9 key
' You could insert a codeline here to check for the string "==>" if you'd like. I use loads of checks to check for the correct panels
TransmitText "1", 5, 13
SendTerminalKey [/COLOR][COLOR=#574123]rcIBMEnterKey
TransmitText "user id", 18, 33[/COLOR]

Does that help you in any way?
 
Last edited:
Upvote 0
The description is good addition to my knowledge :)
well can you check whats is wrong with below given code ? It Opens Reflection from Excel But does not Transmit f9 key and Stops
Code:
Sub CreateReflectionObject()
    Dim Ribm As Object
    Set Ribm = CreateObject("ReflectionIBM.Session")
    Ribm.Visible = True
    With Ribm
        .opensettings 1, "C:\Documents and Settings\Desktop\APL.rsf"
        .WaitForEvent rcEnterPos, "30", "0", 1, 1
        .TransmitTerminalKey rcIBMPf9Key
        .WaitForEvent rcKbdEnabled, "30", "1", 1, 1
        .WaitForEvent rcEnterPos, "30", "0", 1, 1
        .TransmitTerminalKey rcIBMPf9Key
        .WaitForEvent rcEnterPos, "30", "0", 5, 26
        .TransmitANSI "1"
        .TransmitTerminalKey rcIBMEnterKey
        .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
        .WaitForEvent rcEnterPos, "30", "0", 18, 33
        .WaitForDisplayString "ID:", "30", 18, 29
        .TransmitANSI "AKHIAAK"
        .TransmitTerminalKey rcIBMTabKey

        ' Password has not been recorded for security
        Dim hostpassword As String
        hostpassword = ""
        hostpassword = .GetPassword("PASSWORD:", "", "", "")
        .TransmitANSI hostpassword
        .TransmitANSI "50.13.9"
        .TransmitTerminalKey rcIBMEnterKey
    End With
    End
End Sub

above code is the 1st paste if it executes successfully so after that need to copy data from excel and paste in reflection
 
Upvote 0
Let me try to explain what your recorded code does.

Code:
SendTerminalKey [COLOR=#574123]rcIBMPf9Key 'Send F9 key
' You could insert a codeline here to check for the string "==>" if you'd like. I use loads of checks to check for the correct panels
TransmitText "1", 5, 13
SendTerminalKey [/COLOR][COLOR=#574123]rcIBMEnterKey
TransmitText "user id", 18, 33[/COLOR]

Does that help you in any way?

well F9 Key is not being executed what is the solution for it...bro
 
Upvote 0
Hmm... Might be that the MySession object was not instantiated for the SendTerminalKey function.

I have included the full code below and executed it (so it should work now), can you try this version?

I have made my own broker in a class, so I only have to instantiate that class and then it handles it all for me. IMO thats the best solution as I can take that class and export it to other projects and I know that I got all the functions setup as I want them.

Code:
Sub TestTransmit()
    TransmitText "Test2", 22, 16 'Sending the text "Test2" to the screen
    SendTerminalKey rcIBMpf9Key 'Send the Terminal key corresponding to F9
End Sub








'---------------------------------------------------------------------------------------
' Procedure : TransmitText
' Author    : Morten Broberg Kristensen
' Date      : 17.01.2011
' Purpose   : Send text to the host, either to a specified location or to where the
'             cursor might be. Optional TextLength, and also it will truncate to fieldlen
'---------------------------------------------------------------------------------------
Public Function TransmitText(ByVal text As String, Optional Row As Long, Optional Column As Long, Optional TextLength As Long)




    Dim fieldLen As Long
    Dim MySession As Reflection.Session
    Set MySession = GetObject("RIBM")
    
   On Error GoTo TransmitText_Error




    If Not Row = 0 Then 'If we give it a row then first move the cursor!
        MySession.Movecursor Row, Column
        MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Wait 30 sec for keyboard or time out
        MySession.TransmitTerminalKey rcIBMEraseEOFKey 'Clear field
        MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Wait 30 sec for keyboard or time out
    End If
    
    MySession.FindField CursorRow, CursorColumn, rcCurrent, rcAnyField  'Find any field in current field specified by cursorrow and cursorcol and set the properties
    fieldLen = MySession.FoundFieldLength 'Get the foundfieldlength property and use that as amount of chars to retrieve, ie. the full length of the field.
    
    
    
    If Not TextLength = 0 Then 'If textlengh is set then
        text = VBA.Left$(text, Min(TextLength, fieldLen)) 'Truncate text by the lesser of the lengths
    Else
        text = VBA.Left$(text, fieldLen) 'If textlength is not set then truncate by fieldlength
    End If
    
    'And then just send the text
    MySession.TransmitANSI text
    MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Wait 30 sec for keyboard or time out




   Set MySession = Nothing
   On Error GoTo 0
   Exit Function




TransmitText_Error:




  Err.Raise Err.Number, "@[Parser.TransmitText] " & Err.Source, Err.Description




    
    
End Function








Public Function Min(ByVal num1 As Variant, ByVal num2 As Variant) As Variant
On Error GoTo ErrHandler:




    If num1 < num2 Then
        Min = num1
    Else
        Min = num2
    End If
    
Exit Function
ErrHandler:
    Debug.Print "Sommat went wrong"
End Function


'---------------------------------------------------------------------------------------
' Procedure : SendTerminalKey
' Author    : Morten Broberg Kristensen
' Date      : 15.09.2010
' Purpose   : Will try to send the corresponding rc terminalkey
'---------------------------------------------------------------------------------------
Public Function SendTerminalKey(ByVal k As Long) As Boolean
    
   On Error GoTo SendTerminalKey_Error
    
    Dim MySession As Reflection.Session
    Set MySession = GetObject("RIBM")


    MySession.TransmitTerminalKey k
    MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Try to wait for enabled keyboard before we continue








' The code outcommented below is just used internally in my code to count amount of transaction used, and the up'n'down keys are "free" on my system
'    Select Case k
'        Case rcIBMPf7Key
'
'        Case rcIBMPf8Key
'
'        Case Else
'            Transactions = Transactions + 1 'increment the trans-counter
'    End Select
    
   Set MySession = Nothing
   On Error GoTo 0
   Exit Function




SendTerminalKey_Error:




    
Err.Raise Err.Number, "@[Parser.SendTerminalKey] " & Err.Source, Err.Description
    
    
End Function
 
Last edited:
Upvote 0
I have added Added the
Code:
Sub TestTransmit()
       SendTerminalKey rcIBMPf9Key 'Send the Terminal key corresponding to F9
End Sub

And the Transmist Function Code in
VBA Mode and when Reflection is Opened and i Run Set Transmit Macro it Successfully Executes the f9 key :) and am really gald thanks to you...but the issue i want Excel to Open Reflection which is located on the Desktop

MySession.opensettings 1, "C:\Documents and Settings\mintezar\Desktop\APL.rsf"

so that it can open from excel and gets connected and then executes the f9 ki and the moves towards the ID and password screen ...
could it be done!...
with your help alot of things are getting cleared
 
Upvote 0
Great, so we are getting closer.

Now look at the code i wrote, the following code captures a running instance of Reflection
Code:
    [LEFT][COLOR=#333333]Set MySession = GetObject("RIBM")[/COLOR][/LEFT]

But what we are after is actually to create an new instance, and therefore we instead need the following.
Code:
    Set MySession = CreateObject("ReflectionIBM.Session")

This will create a hidden instance of reflection, you can choose to show it with
Code:
MySession.Visible = True
. Afterthis you can load the settingsfile and the use the Myssesion.connect method to connect to the machine.

I would though advice you to move this to a class object instead as to more easily maintain the object. This is because you should only keep one session running, and will have to change my supplied functions to either expect a session object as variable or define a global object somewhere. Therefore a class object would seem more appropriate (also if you want to reuse it in other projects)

I would define the MySession object as a global object for the whole class, and then use the class initializing/termination functions to setup the objectes, and then add a function as to connect it.

Does this make any sense to you?
 
Upvote 0
Just to get you started, I've written the following code

To see how this works, right-click the Project in the Project-explorer and choose "Insert" -> "Class module"
Click the class file, prob. called "Class1" and press F4 to get to properties. Change the name to "ReflectionClass" and set the instancing to Private. Afterwards copy the following code to that file.

Code:
Dim MySession As Reflection.Session 'This object is used throughout the whole class




Private Sub Class_Initialize()
    Set MySession = CreateObject("ReflectionIBM.Session")
End Sub


Private Sub Class_Terminate()
    Set MySession = Nothing
End Sub




Public Sub Connect()
    MySession.Visible = True
    MySession.OpenSettings 1, "Z:\Programming\Reflection Dev\tmp.rsf" 'Change this to your settingsfile
    
    If MySession.Connected = False Then MySession.Connect
    
End Sub
'---------------------------------------------------------------------------------------
' Procedure : TransmitText
' Author    : Morten Broberg Kristensen
' Date      : 17.01.2011
' Purpose   : Send text to the host, either to a specified location or to where the
'             cursor might be. Optional TextLength, and also it will truncate to fieldlen
'---------------------------------------------------------------------------------------
Public Function TransmitText(ByVal text As String, Optional Row As Long, Optional Column As Long, Optional TextLength As Long)




    Dim fieldLen As Long


    
   On Error GoTo TransmitText_Error




    If Not Row = 0 Then 'If we give it a row then first move the cursor!
        MySession.Movecursor Row, Column
        MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Wait 30 sec for keyboard or time out
        MySession.TransmitTerminalKey rcIBMEraseEOFKey 'Clear field
        MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Wait 30 sec for keyboard or time out
    End If
    
    MySession.FindField CursorRow, CursorColumn, rcCurrent, rcAnyField  'Find any field in current field specified by cursorrow and cursorcol and set the properties
    fieldLen = MySession.FoundFieldLength 'Get the foundfieldlength property and use that as amount of chars to retrieve, ie. the full length of the field.
    
    
    
    If Not TextLength = 0 Then 'If textlengh is set then
        text = VBA.Left$(text, Min(TextLength, fieldLen)) 'Truncate text by the lesser of the lengths
    Else
        text = VBA.Left$(text, fieldLen) 'If textlength is not set then truncate by fieldlength
    End If
    
    'And then just send the text
    MySession.TransmitANSI text
    MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Wait 30 sec for keyboard or time out






   On Error GoTo 0
   Exit Function




TransmitText_Error:




  Err.Raise Err.Number, "@[Parser.TransmitText] " & Err.Source, Err.Description




    
    
End Function








Public Function Min(ByVal num1 As Variant, ByVal num2 As Variant) As Variant
On Error GoTo ErrHandler:




    If num1 < num2 Then
        Min = num1
    Else
        Min = num2
    End If
    
Exit Function
ErrHandler:
    Debug.Print "Sommat went wrong"
End Function


'---------------------------------------------------------------------------------------
' Procedure : SendTerminalKey
' Author    : Morten Broberg Kristensen
' Date      : 15.09.2010
' Purpose   : Will try to send the corresponding rc terminalkey
'---------------------------------------------------------------------------------------
Public Function SendTerminalKey(ByVal k As Long) As Boolean
    
   On Error GoTo SendTerminalKey_Error
    


    MySession.TransmitTerminalKey k
    MySession.WaitForEvent rcKbdEnabled, "30", "0", 1, 1 'Try to wait for enabled keyboard before we continue








' The code outcommented below is just used internally in my code to count amount of transaction used, and the up'n'down keys are "free" on my system
'    Select Case k
'        Case rcIBMPf7Key
'
'        Case rcIBMPf8Key
'
'        Case Else
'            Transactions = Transactions + 1 'increment the trans-counter
'    End Select
    


   On Error GoTo 0
   Exit Function




SendTerminalKey_Error:




    
Err.Raise Err.Number, "@[Parser.SendTerminalKey] " & Err.Source, Err.Description
    
    
End Function

Still with me?

Now we got a class going and we can insert the following in any module

Code:
Sub TestOwnClass()    Dim myReflection As ReflectionClass
    Set myReflection = New ReflectionClass
    
    myReflection.Connect
    set myReflection = Nothing
End Sub

See what we did? We moved all the logic to our class, in which we only got one MySession in total, and that Session is shared among the other classes. When we run the connect command on our own class, it loads the settingsfile and connects (you can chose to show or hide it in there if you want).

You can now use our newly create object myReflection with the public functions in our class, ie. TransmitText and SendTerminalKey in the following manner
myReflection.SendTerminalKey and myReflection.TransmitText. Also If you need to keep expanding to other projects etc. you can just export this class and use it again.

Just for reference, the line "Set myReflection = New ReflectionClass" executes the function Class_Initialize() in our class, and "set myReflection = Nothing" runs Class_Terminate() and cleans up, thats why I placed our own creation of objects in these function.

Hope this helps you further along?
 
Upvote 0
am with you bro :)
Step one : Class Modules Created
Step 2 : Name changed from Class1 to ReflectionClass
Step 3 : Changed instancing to Private
Step 4 Copied Code and inserted in ReflectionClass

Well bro TransmitTex "Test2", 22, 16 Is Is not of any use!...cause if f9 key is executing directly like this
Code:
Sub TestTransmit()       
SendTerminalKey rcIBMPf9Key 'Send the Terminal key corresponding to F9 
End Sub

so we wont be needing 22, 16 at all :D cause i was thinking that 1st we need to move to cursor to the location and then f9 key will execute but its not like that rite !!....

step 5 would be ? to add this code in Module 1 ?!!!
to Add
Code:
Sub TestOwnClass()
 Dim myReflection As ReflectionClass
 Set myReflection = New ReflectionClass
myReflection.Connect
set myReflection = Nothing 
End Sub


trying to understand the concept behind your coding :D...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,645
Members
449,461
Latest member
kokoanutt

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