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
 
The code would be like given below but in between it f9key is not being executed after reflection gets connected! and 1 more then we haven't mentioned the location of excel sheet from which reflection will copy the data!
Code:
myReflection.SendTerminalKey rcIBMPf9Key 'This sends our F9Key

Code:
Sub TestOwnClass()
Dim myReflection As ReflectionClass
    Set myReflection = New ReflectionClass
    
    myReflection.Connect
    myReflection.SendTerminalKey rcIBMPf9Key 'This sends our F9Key
    myReflection.TransmitText "1", 5, 13 'Insert 1 at location 5,13
    myReflection.SendTerminalKey rcIBMEnterKey 'Send the Enter key to continue
    myReflection.TransmitText "USER", 18, 33 'Change the USER to your USER-ID
    myReflection.TransmitText "PASSWORD", 18, 33 'Change the PASSWORD to your PASSWORD and also change to the correct location
    myReflection.SendTerminalKey rcIBMEnterKey 'Send the Enter key to continue
    myReflection.TransmitText "50.7.13", 23, 16 'Put the text 50.7.13 at the command line
    myReflection.SendTerminalKey rcIBMEnterKey 'Send the Enter key to continue
    Set myReflection = Nothing
End Sub

and the below given will be placed in Class Modules ?
Code:
Dim lng_ContainerIterator as long 'This is to keep track of which line in the Sheet we are processing
Dim lng_LastContainerRow as long 'This var will hold the last container row


lng_LastContainerRow = ActiveSheet.Cells(ActiveSheet.Rows.count, "A").End(xlUp).Row 'This finds the first cell with content starting from the buttom and up, should also be the last cell in a range without empty rows.




'I assume your data start at row 2 and theres columng headers in row 1
For lng_ContainerIterator = 2 to lng_LastContainerRow
	myReflection.TransmitText Cells(lng_ContainerIterator,"A"), 3, 11 'Send the content of column A in the current row to 3,11
	myReflection.SendTerminalKey rcIBMEnterKey 'Send the Enter key to continue
	myReflection.TransmitText Cells(lng_ContainerIterator,"B"), 4, 11 'Send the content of column B in the current row to 4,11
	myReflection.SendTerminalKey rcIBMEnterKey 'Send the Enter key to continue
next lng_ContainerIterator 'Do it again with the next row

and in Class Module i already have placed your given function coding

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, "C:\Documents and Settings\sshahzad\Desktop\Reflection.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
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
hi guys i want help i want to call "terminal emulator WRQ Reflection for Unix/Digital" and open its file test.r2w through excel macro or any batch or vb scripting... is it possible to do that?
 
Upvote 0
hi guys i want help i want to call "terminal emulator WRQ Reflection for Unix/Digital" and open its file test.r2w through excel macro or any batch or vb scripting... is it possible to do that?

Hello & welcome to the forum,

I played around with it when I was looking for the same thing and found this to work:
Code:
    Dim wbThis As Workbook
    Set wbThis = ThisWorkbook
    RUNWRQ = "C:\Program Files\Reflection\r2win.exe " & wbThis.Path & "\test.r2w"
    Shell RUNWRQ, vbNormalFocus
This is an Excel Macro. I use the wbThis.Path so I can place the Excel workbook running the macro that calls test.r2w in the same directory path.

I don't know if there is another way. Hopefully someone else will respond that uses a different way.
 
Upvote 0
hey thanks buddy little more help... actully i found one script to run excel file and its macro automatically through *.vbs script

" Sub LaunchMacro() Dim xl
Dim xlBook
Dim sCurPath


sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Set xl = CreateObject("Excel.application")
Set xlBook = xl.Workbooks.Open(sCurPath & "\mw1.xlsm", 0, True)
xl.Application.Visible = True
xl.Application.run "mw1.xlsm!Macro1"
xl.DisplayAlerts = true
xlBook.saved = True
xl.activewindow.close
xl.Quit


Set xlBook = Nothing
Set xl = Nothing"
so is it possible to open test.r2w file and run WRQ Reflection macro automatically? :)


Hello & welcome to the forum,

I played around with it when I was looking for the same thing and found this to work:
Code:
    Dim wbThis As Workbook
    Set wbThis = ThisWorkbook
    RUNWRQ = "C:\Program Files\Reflection\r2win.exe " & wbThis.Path & "\test.r2w"
    Shell RUNWRQ, vbNormalFocus
This is an Excel Macro. I use the wbThis.Path so I can place the Excel workbook running the macro that calls test.r2w in the same directory path.

I don't know if there is another way. Hopefully someone else will respond that uses a different way.
 
Upvote 0
so is it possible to open test.r2w file and run WRQ Reflection macro automatically? :)

I'm not quite sure there is an Excel command line argument that will run a specific Macro inside Reflection. But, the way I do what you want is not through Excel, but through Reflection itself. Open your Reflection settings file and go to the Connection Setup and choose a Connection Macro, which runs whenever that settings file is opened.
 
Upvote 0
That is cool! thanks! i will try this :)

I'm not quite sure there is an Excel command line argument that will run a specific Macro inside Reflection. But, the way I do what you want is not through Excel, but through Reflection itself. Open your Reflection settings file and go to the Connection Setup and choose a Connection Macro, which runs whenever that settings file is opened.
 
Upvote 0
Yeah, it's really nice. Your Reflection Macro can auto-logon to it's server, run it's routines, then auto-logoff and close the Refl window all without user intervention. Some of this based on some other setups in the 'Connection Setup' menu in Refl. Gotta check it out.
 
Upvote 0
Hey thanks for the help really appreciate :) u really made my life easy
I got one probs. if u can help :) actully before few months i have tried to save macro in r2w for auto login and i did mistake and all people from my team whenever they were opening this r2w file from their desktop they automatically started to get login with my credentials.... later i have deleted my macro. but now since few months whenever my team is opening that r2w file from their own desktop... it is showing error " No "Login Macro found" (Login was the name of my macro) could you help me to remove this error? and if possible can you also tell me the script to close r2w file automatically? :)



Yeah, it's really nice. Your Reflection Macro can auto-logon to it's server, run it's routines, then auto-logoff and close the Refl window all without user intervention. Some of this based on some other setups in the 'Connection Setup' menu in Refl. Gotta check it out.
 
Upvote 0
Hi Guys, I know how to call WRQ Reflection and its test.r2w file from excel macro but i don't know how to close it automatically via excel macro or any kind of vb scripting... can you please help! :)
 
Upvote 0
This may rely on what version of WRQ Reflection you are running, but just go into the Reflection Menu item 'Connection Setup', 'More Setting' and click on the 'Exit on Disconnect' option. Make sure to Save the Reflection settings file.

With this option turned on, then by either the User or your Reflection Macro simply logging off the server, then the Reflection window will close itself.
 
Upvote 0

Forum statistics

Threads
1,215,415
Messages
6,124,768
Members
449,187
Latest member
hermansoa

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