Skip to main content

How to use WaitForStrings Methods

  • May 9, 2017
  • 6 replies
  • 3 views

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


#Desktop
#Reflection

6 replies

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


#Desktop
#Reflection
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.

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.
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...

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...
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...

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...
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

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
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

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
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,"