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
 
i added
this :
Code:
Sub TestTransmit()     
TransmitText("This is a testTxt",4,10) 
End sub
but it is showing error saying expected =
then i replaced did this
Code:
 TransmitText.Movecursor , 4, 10
still showing error
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Oh sorry I forgot that when calling a function like that you write

Code:
TransmitText "Test", 4,10

Are thgere any other errors you are getting? If so, which?
 
Upvote 0
well i have place your coding like give below but! when i run TestTransmit it gives error that After End Sub or end Function only comment should appear ! not running

Code:
Sub TestTransmit()
      TransmitText "Test", 4, 10
End Sub
Dim MySession As Reflection.Session
Set MySession = New Session

'---------------------------------------------------------------------------------------
' 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
End Sub
 
Upvote 0
The error you are getting basically means that you are executing code outside of a sub or function. And from the looks of your postings, it indicates the following lines

Dim MySession As Reflection.Session
Set MySession = New Session

Try moving these to right after the following line

Dim fieldLen As Long
 
Upvote 0
moves
Dim MySession As Reflection.Session
Set MySession = New Session
right after
Dim fieldLen As Long like this :

Dim fieldLen As Long
Dim MySession As Reflection.Session
Set MySession = New Session

but it is stopping at & compile error : user-defined type not defined
Public Function TransmitText(ByVal text As String, Optional Row As Long, Optional Column As Long, Optional TextLength As Long)
Dim MySession As Reflection.Session
 
Upvote 0
Hi again

The error you are getting is likely because you are missing the reference from post #20.

"WRQ Reflection for IBM 12.0 Object Library" or "Reflection for IBM Session", filename : R8ole32.olb.

Try to find this by, clicking "Tools -> References" and then find that reference on the list.

Also I have noticed that I am using a Minimum function in my code, so in case you don't have one of those lying around, here's an example

Code:
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:
    MsgBox "Something went wrong"
End Function


Also a last error in your code is the last end Sub after the end function.

Subs and function must be enclosed like following

Function FunctionName
...Do fancy stuff
End function

Sub SubroutineName
... Do sneaky stuff
End sub

Hell I'll just include the whole module here, I was also missing the code to catch the correct connection running(also I wasn't cleaning up), anyways, try the following code
Code:
Sub TestTransmit()
      TransmitText "Tyst2", 22, 16
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


 
Upvote 0
i found R8ole32.olb. reference and have added it from VB tool reference & I have changed

TransmitText "Tyst2", 22, 16 to TransmitText "Tyst2", 5, 72 because this is the cursor location where F9 is but its not transmitting F9
so that it can move to the next screen
it gives Run-time error '4087'
application defined or object defined error
 
Upvote 0
Oh are you trying to transmit the Function-button F9?

My function above is only to send text across, in the test case above it is sending the text "Tyst2" (was supposed to be test, but i mistyped) to the location row 5, column 72.

Here's another function you can throw below the TrasmitText function

Code:
'---------------------------------------------------------------------------------------
' 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:


    [LEFT][COLOR=#3E3E3E]Err.Raise Err.Number, "@[Parser.[/COLOR]SendTerminalKey[COLOR=#3E3E3E]] " & Err.Source, Err.Description[/COLOR][/LEFT]
    
    
End Function


With these two functions you can do the following
Code:
[COLOR=#3E3E3E]TransmitText "Test2", 22, 16 'Sending the text "Test2" to the screen
[/COLOR]SendTerminalKey rcIBMpf9Key 'Send the Terminal key corresponding to F9
 
Last edited:
Upvote 0

Forum statistics

Threads
1,217,350
Messages
6,136,055
Members
449,986
Latest member
Mark39841

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