marshallgrads Absent Member.
Absent Member.
3366 views

How to use WaitForStrings Methods

Hello,
I am new to the Micro Focus Reflections Desktop Pro version (v16) of software. The programming language structure is substantially different from the Previous version of Reflections (v14). I would like to see if someone can post or provide a snippet of code that show the differences in using the various WaitForStrings methods that are now found in the new version of Pro?

WaitForStrings
WaitForStrings2
WaitForStrings3
WaitForStrings4 ??

=====================================================================================
here is an example of how the older version of Reflection use to handle the waitforstrings method. I understand how it works because the help file for the older version gave a very good example of how it was used.
Syntax WhichString = object.WaitForStrings(StringsArray, [Timeout], [Options])

Description

Session.Parent.Application.WaitForStrings (StringsArray, [Timeout], [Options])

Arguments

StringsArray Argument Type: String array
Required
Specifies one or more strings for which to wait. Reflection considers case (the incidence of uppercase and lowercase letters) in testing incoming data for a matching string.
Timeout Argument Type: String
Optional
Specifies the amount of time to wait for one of the specified strings to be received. The string is specified in HH:MM:SS.hh format. If this argument is omitted or is empty (""), Reflection waits indefinitely if none of the strings is received.

Options Argument Type: Enumeration
Optional
Specifies additional, non-default behavior for the method. There are three options for this method:
rcAllowKeystrokes - Specifies that the user is allowed to enter keystrokes in the terminal window during the wait.

rcNoDisplay - Specifies that incoming datacomm characters should not be displayed in the terminal window.

rcNoTranslation - Specifies that the StringsArray parameter contains binary data. Binary data is matched exactly as it is received from the host without performing host-to-PC character set translation.

You can combine two or more options using the addition operator (+). For example: rcAllowKeystrokes + rcNoDisplay.

Return

WhichString Return type: Integer
A number indicating which item in the StringsArray array was found. If the first item is found, 1 is returned; if the second item is found, 2 is returned; and so on. If none of the strings are received before the Timeout time expires, False (0) is returned. If no Timeout is specified, this method cannot return False.
=====================================================================================

Example

This example waits 20 seconds for one of three prompts to be received from the host and transmits a different string (plus carriage return) depending upon which prompt is received.

Sub WhichPromptDemo()
Dim myArray(1 To 3) As String
myArray(1) = "Prompt 1:"
myArray(2) = "Prompt 2:"
myArray(3) = "Prompt 3:"
Select Case Application.WaitForStrings(myArray, "20", rcAllowKeystrokes)
Case 1:
Session.Transmit "Text1" & Chr$(rcCR)
Case 2:
Session.Transmit "Text2" & Chr$(rcCR)
Case 3:
Session.Transmit "Text3" & Chr$(rcCR)
Case Else
MsgBox "Timed out with no recognized prompt."
End Select
End Sub
0 Likes
6 Replies
Micro Focus Contributor
Micro Focus Contributor

Re: How to use WaitForStrings Methods

Hi,

The difference in the various WaitForStrings methods in Reflection Desktop lies in the different amount of arguments (parameters) each of them take.

Here is a comparison: (btw. WaitForString has the same syntax as WaitForStrings)

[table="width: 100%, class: grid"]

object.WaitForString( _
ByVal text As String _
) As ReturnCode


object.WaitForStrings2( _
ByRef text As String(), _
ByVal timeout As Long _
) As ReturnCode


object.WaitForStrings3( _
ByRef text As String(), _
ByVal timeout As Long, _
ByVal option As WaitForOption _
) As ReturnCode


object.WaitForStrings4( _
ByRef text As String(), _
ByVal timeout As Long, _
ByRef stringidx As Long, _
ByVal option As WaitForOption _
) As ReturnCode



text
The text to wait for.
text
Array that specifies one or more strings for which to wait.
timeout
wait timeout value (milliseconds). Value of 0 indicates wait indefinitely.
text
Array that specifies one or more strings for which to wait.
timeout
wait timeout value (milliseconds). Value of 0 indicates wait indefinitely.
option
The wait options. Multiple options can be combined using the OR operator.

text
O-based string array that specifies one or more strings for which to wait.
timeout
The wait timeout value (in milliseconds).
stringidx
1-based index indicating string in text array that satisfied condition. (For the first array element, stringidx=1.)
option
Wait options. Multiple options can be combined using the OR operator.

[/table]

Now, if you are running your code in the "legacy" part of the VBA project, you can still use the syntax from Reflection 14.1 as you described in your post.

I'm sure you know this, but when you hit the F1 key after entering a (valid) method name, Reflection help will open with the full syntax explained.
[INDENT][/INDENT]

Just as a side note (and not related to the WaitForStrings discussion), there are some limits with regards to the backwards compatibility of Reflection 14.1 macros, which you can find here.

Matthias

Micro Focus Customer Care

0 Likes
marshallgrads Absent Member.
Absent Member.

Re: How to use WaitForStrings Methods

Thanks Matt,
I am just now getting to use the newer Micro Focus Reflection for Desktop Pro version (v16). It is a completely different animal compared to the previous Reflection product (v14). The help feature of the new version is not as detailed and seems to be void of programming examples that the legacy product had. Although I can see from your above example that the different .WaitForString(s) methods (I may be using the wrong descriptor) are different based on the extensions that each subsequent one has 1 vs 2 vs 3 vs 4. In the older product it appeared necessary to Dim a Choice statement, but this does not seem to be apparent in the newer version? Is this true? Do you utilize a SELECT CASE statement to then branch out depending on what "string" you are returning? Coming from a non programmer point of view, I am learning as I go. I can understand some concepts, but in depth programmer language eludes me at this point..

Say I wanted to be able to branch my code depending on what my computer system prompt displayed on screen as I entered through an option I have.
If during the processing I could expect one of these replies, how would the actual code be. In the legacy version (v14) it was straightforward as the the example clearly shows. The new programming structure is ambiguous to me on how to branch and whether or not something like a Select Case statement is required or needed??

1. "HELLO BUTCH"
2. "Goodbye Butch"

"example = object.WaitForStrings(myArray, "20", rcAllowKeystrokes)

myArray = the string or strings that you could have (ex: "HELLO BUTCH" or "Goodbye Butch"?
20 = the number of seconds or milliseconds that the program will wait for a reply containing one of the above choices?
rcAllowKeystrokes = The computer will allow the user to enter keystokes on the keyboard, if you omit this, then the user keyboard will be prohibited from being used and no user input will be allowed.

Is the myArray really something like this?
myArray(1) = HELLO BUTCH
myArray(2) = Goodbye Butch


Sorry to be so basic in my questions but it just does not make sense yet...
0 Likes
marshallgrads Absent Member.
Absent Member.

Re: How to use WaitForStrings Methods

I have been reading a little and believe I came across this on the Micro Focus website - Handling Asynchronous Behavior

URL = http://docs.attachmate.com/reflection/16.0/vba-prog-guide/#asynchronous-behavior.html

I believe this is attempting to convey to the reader how to use the .WaitForString(s) methods and how to handle ever changing prompts returned by the HOST system to a users terminal. I just have to read it and digest it a little...
0 Likes
marshallgrads Absent Member.
Absent Member.

Re: How to use WaitForStrings Methods

As a side note

object.WaitForStrings3( _
ByRef text As String(), _
ByVal timeout As Long, _
ByVal option As WaitForOption _
) As ReturnCode



is this also a way of writing -

object.WaitForStrings3(ByRef text As String, ByVal timeout As Long, ByVal option As WaitForOption) As ReturnCode
0 Likes
marshallgrads Absent Member.
Absent Member.

Re: How to use WaitForStrings Methods

Red = User types data on keyboard
Purple = Computer responds with input on screen but user is not allowed or present with keyboard entry
Green = User is allowed to type on keyboard and enter a response that is appropriate to the prompt.


Scenario 1

Line 1a Select Laboratory DHCP Menu Option: Process data in lab menu
Line 1b Select Process data in lab menu Option: clear instrument/worklist data
Line 1c Select LOAD/WORK LIST NAME: polyMEDCO
Line 1c-1<<< No data in LAH global for this load/work list >>> <no user input>
Line 1d Operation not complete <no user input>
Line 1e Select Process data in lab menu Option: <this is a menu item awaiting user input>

Sub POLYMEDCO()
' Generated by the Reflection Macro Recorder on 05-17-2017 14:53:08.08.
' Generated by Micro Focus Reflection Desktop Pro (16.0.308.0).

Dim osCurrentScreen As Screen
Dim osCurrentTerminal As Terminal
Dim returnValue As Integer

Const NEVER_TIME_OUT = 0

Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M

Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen

LF = Chr(10)
CR = Chr(13)

osCurrentScreen.SendKeys "Process data in lab menu"
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Select Process data in lab menu Option: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If

osCurrentScreen.SendKeys "clear instrument/worklist data"
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Select LOAD/WORK LIST NAME: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If

osCurrentScreen.SendKeys "polyMEDCO"
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Select Process data in lab menu Option: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If

osCurrentScreen.SendControlKey ControlKeyCode_Return

Exit Sub

End Sub



Scenario 2
Line 2a Select Laboratory DHCP Menu Option: Process data in lab menu
Line 2b Select Process data in lab menu Option: clear instrument/worklist data
Line 2c Select LOAD/WORK LIST NAME: URINALYSIS/URINE MICRO
Line 2d Select one of the following: <no user input>
Line 2e
Line 2f 0 All Results for this Load/Worklist
Line 2g 1 By Date Results First Received
Line 2h 2 By Date Results Last Updated
Line 2i
Line 2j Clear Results: <this is a menu item awaiting user input>


In looking at the above scenarios you can see that lines a-c are identical in each, it is line 1e “Select Process data in lab menu Option:” and Line 2j “Clear Results:” that I want to be able to identify in my code and believe that using the WaitForStrings3 method allows for this? I just do not know how to code for this in my macro coding?

Sub URINES()
' Generated by the Reflection Macro Recorder on 05-17-2017 14:53:45.06.
' Generated by Micro Focus Reflection Desktop Pro (16.0.308.0).

Dim osCurrentScreen As Screen
Dim osCurrentTerminal As Terminal
Dim returnValue As Integer

Const NEVER_TIME_OUT = 0

Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M

Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen

LF = Chr(10)
CR = Chr(13)

osCurrentScreen.SendKeys "Process data in lab menu"
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Select Process data in lab menu Option: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If

osCurrentScreen.SendKeys "clear instrument/worklist data"
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Select LOAD/WORK LIST NAME: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If

osCurrentScreen.SendKeys "URINALYSIS/URINE MICRO "
osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Clear Results: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If

osCurrentScreen.SendControlKey ControlKeyCode_Return
'Wait for a string on the host screen before continuing
returnValue = osCurrentScreen.WaitForString3(LF & "Select Process data in lab menu Option: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
If (returnValue <> ReturnCode_Success) Then
Err.Raise 11001, "WaitForString3", "Timeout waiting for string.", "VBAHelp.chm", "11001"
End If

osCurrentScreen.SendControlKey ControlKeyCode_Return

Exit Sub

End Sub
0 Likes
marshallgrads Absent Member.
Absent Member.

Re: How to use WaitForStrings Methods

Here is what I was able to come up with after receiving some very informative help from Microfucus. The WaitForStrings4 method is what is needed to be used. This method allows for the branching out structure that I need/want based on the changing prompts from the computer system.


Sub CLEAR_INSTRUMENTS_NEW()
' Generated by the Reflection Macro Recorder on 05-17-2017 14:53:08.08.
' Generated by Micro Focus Reflection Desktop Pro (16.0.308.0).
' AS OF 5/22/2017 THIS VERSION SEEMS TO WORK AS DESIGNED. THE WAITFORSTRINGS4 METHOD IS THE BOMB !!
' BUTCH JONES 5/2017

Dim osCurrentScreen As Screen
Dim osCurrentTerminal As Terminal
Dim SPLITTEST As Variant ' all Array's must be Dim as variant data type unless specifically needed for others.
Dim RETVAL As ReturnCode
Dim returnStringIndex As Long

Const NEVER_TIME_OUT = 0

Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M

Set osCurrentTerminal = ThisFrame.SelectedView.control
Set osCurrentScreen = osCurrentTerminal.Screen

LF = Chr(10)
CR = Chr(13)


'====================================================================
'IN THIS SEGMENT OF CODE YOU ARE DIMENSIONING AN ARRAY OF DATA. THIS IS A SIMPLE ARRAY WITH ONLY TWO CHOICES
'FOR THE NEW MICRO FOCUS REFLECTION DESKTOP PRO version YOU MUST USE AN ARRAY BASE OF 0 (ZERO). IN OTHER WORDS
'YOUR ARRAY DIM STATEMENT MUST BE FROM 0 TO SOME NUMBER, DEPENDING ON HOW MANY DIFFERENT CHOICES YOU ARE LOOKING
'FOR IN YOUR STRING.

Dim CHOICE(0 To 1) As String
CHOICE(0) = "Clear Results:" 'IF DATA IS AVAILABLE YOU GET THIS
CHOICE(1) = "Select Process data in lab menu Option:" ' IF NO DATA YOU GET THIS

'<=====================================================>

LISTS = "COAG,XE-5000,XT-4000i,URINALYSIS/URINE MICRO,MISC URINALYSIS TESTS,DIFFS/S+4," & _
"MISC HEMATOLOGY TESTS,5600 BOTH,GENEXPERT,NOVA,SED RATES (CDD-WK),SPECIAL HEMATOLOGY," & _
"POLYMEDCO,TOSOH8,VIDAS,"

SPLITTEST = Split(LISTS, ",")
'DATA WILL BE SPLIT AND PARSED ON THE COMMA SEPARATING EACH LOADLIST/INSTRUMENT
'SPLITTEST(0) = COAG
'SPLITTEST(1) = XE-5000
'SPLITTEST(2) = XT-4000i
'SPLITTEST(3) = URINALYSIS/URINE MICRO
'SPLITTEST(4) = MISC URINALYSIS TESTS
'SPLITTEST(5) = DIFFS/S+4
'SPLITTEST(6) = MISC HEMATOLOGY TESTS
'SPLITTEST(7) = 5600 BOTH
'SPLITTEST(8) = GENEXPERT
'SPLITTEST(9) = NOVA
'SPLITTEST(10) = SED RATES (CDD-WK)
'SPLITTEST(11) = SPECIAL HEMATOLOGY
'SPLITTEST(12) = POLYMEDCO
'SPLITTEST(13) = TOSOH8
'SPLITTEST(14) = VIDAS
'SPLITTEST(15) = ETC......
'<=====================================================>



osCurrentScreen.SendKeys "^Process data in lab menu"
osCurrentScreen.SendControlKey ControlKeyCode_Return

returnValue = osCurrentScreen.WaitForString3(LF & "Select Process data in lab menu Option: ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
osCurrentScreen.SendKeys "Clear instrument/worklist"
osCurrentScreen.SendControlKey ControlKeyCode_Return


For Each x In SPLITTEST

'MsgBox "YOUR TEST IS: " & SPLITTEST(8)

returnValue = osCurrentScreen.WaitForString3(LF & "Select LOAD/WORK LIST NAME: ", NEVER_TIME_OUT, WaitForOption_AllowKeystrokes)
osCurrentScreen.SendKeys x 'SEND THE APPROPRIATE TEST FROM THE SPLITTEST() ARRAY WHICH IS CONTAINED AT THE VALUE "x"
osCurrentScreen.SendControlKey ControlKeyCode_Return

'IF YOU ENTER A LOADLIST AND NO DATA IS AVAILABLE FOR REMOVAL THEN YOU GET AN
'AUTOMATIC REPLY THAT STATES - <<< No data in LAH global for this load/work list >>>
'VISTA THEN SENDS A NON PRINTABLE CHARACTER LINE OF - Operation not complete
'IT THEN MOVES TO THE MENU OPTION - Select Process data in lab menu Option:

RETVAL = osCurrentScreen.WaitForStrings4(CHOICE(), NEVER_TIME_OUT, returnStringIndex, WaitForOption_AllowKeystrokes)

Select Case returnStringIndex
'AFTER MUCH TESTING, I HAVE CONCLUDED THAT THE returnStringIndex IS THE IMPORTANT FACTOR HERE.
'THIS COMPONENT IS THE 3rd PIECE OF THE WaitForStrings4 method being used. Using any of the other
'WaitForStrings METHOD WILL NOT ALLOW FOR THE MATCHING OF CHANGING PROMPTS. ONLY THE WaitForStrings4
'METHOD ALLOWS FOR THIS DATA INTERPRETATION IN THE NEWER REFELECTION PRODUCT.
'IT MATCHES UP TO THE 'CHOICE' ARRAY ABOVE AND IS WHAT IS NEEDED TO BRANCH OUT WITH THE BELOW LISTED
'SELECT CASE STATEMENT.
'DO NOT CONFUSE THE ARRAY INDEX OF CHOICE(0) AND CHOICE(1) WITH THE returnStringIndex. THEY ARE TWO
'DIFFERENT INDEXES. THE returnStringIndex IS MORE HUMAN READABLE AND RETURNS THE FIRST OR SECOND CHOICE
'IN YOUR LIST WHILE THE ARRAY() PARSING RETURNS COMPUTER CODE/INTERPRETATIONS.

Case 1:

' MsgBox "case1"
' THE SCREEN PROMPT SHOULD DISPLAY - "Clear Results:"
osCurrentScreen.SendKeys "1"
osCurrentScreen.SendControlKey ControlKeyCode_Return


returnValue = osCurrentScreen.WaitForString3(LF & "Select Cutoff Date/Time:", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
osCurrentScreen.SendKeys "N-36H"
osCurrentScreen.SendControlKey ControlKeyCode_Return

returnValue = osCurrentScreen.WaitForString3(LF & "Is this correct?", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
osCurrentScreen.SendKeys "YES"
osCurrentScreen.SendControlKey ControlKeyCode_Return

returnValue = osCurrentScreen.WaitForString3(LF & "Select Process data in lab menu Option:", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes)
osCurrentScreen.SendKeys "Clear instrument/worklist"
osCurrentScreen.SendControlKey ControlKeyCode_Return

Case 2:

' MsgBox "case2"

' THE SCREEN PROMPT SHOULD DISPLAY - "Select Process data in lab menu Option:"
osCurrentScreen.SendKeys "Clear instrument/worklist"
osCurrentScreen.SendControlKey ControlKeyCode_Return

End Select

Next


Exit Sub

End Sub

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.