Page 4 of 7 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 61

Reflections WRQ VBA

This is a discussion on Reflections WRQ VBA within the General Excel Discussion & Other Questions forums, part of the Question Forums category; let me tell you the complete procedure 1st of reflection is already opened and connected with the Host ip and ...

  1. #31
    New Member
    Join Date
    Aug 2011
    Posts
    49

    Default Re: Reflections WRQ VBA

    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

  2. #32
    New Member
    Join Date
    Jun 2012
    Posts
    13

    Default Re: Reflections WRQ VBA

    Let me try to explain what your recorded code does.

    .WaitForEvent rcEnterPos, "30", "0", 1, 1 Make the client wait a maximum of 30 seconds for the cursor to reach row 1, column 1
    .TransmitTerminalKey rcIBMPf9Key Transmit the F9 button to the client
    .WaitForEvent rcKbdEnabled, "30", "0", 1, 1 Wait 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, 13 Wait max 30 sec for cursor to enter pos 5, 13
    .WaitForDisplayString "==>", "30", 5, 9 Wait max 30 secs for the string "==>" to appear at location 5,9
    .TransmitANSI "1" Send the text "1"
    .TransmitTerminalKey rcIBMEnterKey Transmit the ENTER button
    .WaitForEvent rcKbdEnabled, "30", "0", 1, 1 Wait max 30 secs for the keyboard to be enabled
    .WaitForEvent rcEnterPos, "30", "0", 18, 33 Wait max 30 secs for the cursor to enter position 18,33
    .WaitForDisplayString "ID:", "30", 18, 29 Wait max 30 secs for the string "ID:" to appear at location 18,29
    .TransmitANSI "user id" Send text "user id" to the client
    .TransmitTerminalKey rcIBMTabKey Send 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 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 rcIBMEnterKey
    TransmitText "user id", 18, 33
    Does that help you in any way?
    Last edited by broberg; Jun 21st, 2012 at 04:59 AM. Reason: sp

  3. #33
    New Member
    Join Date
    Aug 2011
    Posts
    49

    Default Re: Reflections WRQ VBA

    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

  4. #34
    New Member
    Join Date
    Aug 2011
    Posts
    49

    Default Re: Reflections WRQ VBA

    is there anyways to attach excel attachment ? in this forum ? so tat you can get the better picture

  5. #35
    New Member
    Join Date
    Aug 2011
    Posts
    49

    Default Re: Reflections WRQ VBA

    Quote Originally Posted by broberg View Post
    Let me try to explain what your recorded code does.

    Code:
    SendTerminalKey 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 rcIBMEnterKey
    TransmitText "user id", 18, 33
    Does that help you in any way?
    well F9 Key is not being executed what is the solution for it...bro

  6. #36
    New Member
    Join Date
    Jun 2012
    Posts
    13

    Default Re: Reflections WRQ VBA

    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 by broberg; Jul 3rd, 2012 at 06:09 AM. Reason: wording and spelling

  7. #37
    New Member
    Join Date
    Aug 2011
    Posts
    49

    Default Re: Reflections WRQ VBA

    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

  8. #38
    New Member
    Join Date
    Jun 2012
    Posts
    13

    Default Re: Reflections WRQ VBA

    Great, so we are getting closer.

    Now look at the code i wrote, the following code captures a running instance of Reflection
    Code:
        
    Set MySession = GetObject("RIBM")
    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?

  9. #39
    New Member
    Join Date
    Jun 2012
    Posts
    13

    Default Re: Reflections WRQ VBA

    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?

  10. #40
    New Member
    Join Date
    Aug 2011
    Posts
    49

    Default Re: Reflections WRQ VBA

    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 by xcruc1at3r; Jul 9th, 2012 at 08:21 AM.

Page 4 of 7 FirstFirst ... 23456 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com