Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having difficulty with an If Statement. 1

Status
Not open for further replies.

sfchtm

Technical User
Sep 29, 2011
6
US
The second If Statement is completely ignored when this runs in refection. I have tried it several different ways. I want to keep the code as simple as possible because it will be modified in the future by end users.

Sub Test()

On Error GoTo ErrorHandler

Const NEVER_TIME_OUT = 0
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim yArray(3)

CR = Chr(Reflection2.ControlCodes.rcCR)

yArray(0) = "A!A"
yArray(1) = "B!B"
yArray(2) = "C!C"
yArray(3) = "D!D"

With Session

For i = 0 To 3


If .WaitForString("Enter:", NEVER_TIME_OUT, rcAllowKeystrokes) Then
.Transmit yArray(i)
.Transmit CR
End If

If .WaitForString(" ...OK? Yes//", NEVER_TIME_OUT, rcAllowKeystrokes) Then
Retest
End If

Next

End With

Exit Sub

ErrorHandler:
Session.MsgBox Err.description, vbExclamation + vbOKOnly

End Sub
 


hi,

I believe that the WaitForString method need a SCREEN object reference, not a SESSION object.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I am using Reflection. According to the help and everything else I have read the syntax is correct, I'm missing something else?
It waits for the string of text. I can move the end of the Loop (Next) above the second if statement and the Macro runs with out a hitch unless the string ...OK? Yes// comes up the I have to hit CR twice and it will continue. I would like to be able to hit run and walk away...As of now the array is accually 38 long and growing. Like i said the macro steps through the array just fine unless...

Function WaitForString(String As String, [Timeout], [Options]) As Boolean
Member of Reflection2.Session
Wait for a specified string from the host
 
i'm not familiar with Reflection,but in using Attachmate, it states:

Description

Waits until the specified text appears on the screen. This method will wait for the amount of time set in the System.TimeoutValue.

not sure if this helps or not

 
Maybe I'm completely out in left field? I don't have any problem with the array, it runs like a champ. The problem is the conditional statement. It is either completely ignored as if it isn't there at all. Or runs as if it isn't conditional. Might as well not have the If...Then....End If at all. Runs like it is a required statement and stops the macro waiting on the prompt. Any suggestions would be great.



Sub Test()
'
' Per clinic
' Macro created 8/8/2011 by vhamoumorelh
'
Const NEVER_TIME_OUT = 0
Dim yArray(3)

yArray(0) = "A!A"
yArray(1) = "B!B"
yArray(2) = "C!C"
yArray(3) = "D!D"

On Error GoTo ErrorHandler:

For i = 0 To 3

Reflection2.Session.WaitForString "Select Patient name or Clinic name:", NEVER_TIME_OUT, rcAllowKeystrokes
Reflection2.Session.Transmit yArray(i)
Reflection2.Session.Transmit vbCr

'Next - Conditional statement does not run until array is complete?

If Reflection2.Session.WaitForString(" ...OK? Yes// ", NEVER_TIME_OUT, rcAllowKeystrokes) Then
Retest
End If

Next '- Conditional statement runs as if required with each instance of array? Stops the Maro waiting on prompt.

Exit Sub

ErrorHandler:
MsgBox "Failed" _
& vbCrLf & vbCrLf & Err.description, vbCritical


End Sub

Sub Retest()
On Error GoTo ErrorHandler

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

LF = Chr(Reflection2.ControlCodes.rcLF)
CR = Chr(Reflection2.ControlCodes.rcCR)

With Session

.StatusBar = "Waiting for Prompt: ...OK? Yes//"
.WaitForString LF & " ...OK? Yes// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit CR
.Transmit CR

End With
Exit Sub

ErrorHandler:
Session.MsgBox Err.description, vbExclamation + vbOKCancel


End Sub
 


What is [highlight]Reflection2[/highlight]?

Along with Session, it is UNDECLARED and UNASSIGNED!!!

See faq99-4069

In Attachmate Extra, the object reference for the WaitForString method is a SCREEN object, not a session object.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Reflection for UNIX and OpenVMS is a connectivity software application. Reflection establishes and maintains communications between a host computer and your PC running Microsoft Windows XP, Windows 2000 Server or Workstation, or Windows Server 2003. With Reflection, your PC emulates, or operates like a VT-series, ADDS, DG, Unisys T27, WYSE terminal, or Linux console. This allows you to communicate with the host just as if you were using a terminal, and maintain a host connection while running other Windows applications.

Reflection emulates the following terminals: VT525, VT520, VT510, VT420, VT320, VT220, VT102, VT52, AT386, BBS-ANSI, SCO-ANSI, DG215, ADDS VP2, WYSE 50 and 60, IBM 3151, Unisys T27, TVI 955, TVI 950, VT-UTF8, QNX, and XTERM terminals. Support for the Linux console is also included.

©1994-2006 Attachmate Corporation
 
The issue is not the Reflection2.Session.WaitForString(" ...OK? Yes// ", NEVER_TIME_OUT, rcAllowKeystrokes)it is the If...Then...End If. It seems as if it is ignored? Or could it be because it is running in Reflection?
 


You really did not answer my question/issue, TWICE stated on TWO different posts. Your problem, not mine!

Try testing in a loop
Code:
Do
  if YourScreenObject.WaitForString(YourString) then 
      Retest
      exit do
  end if
Loop


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I tried the loop. I tried setting the screen as an object several different ways. I have attached a screen shot of the object browser showing how I got the Reflection2.Session.WaitForString - It came direct from the object browser. This is an enterprise environment and I have never tried to write a macro to run on an user desktop in reflection(Attachmatte) so I may be way out in left field here...It is for an end user and she wants to be able to and to the array as needs change...
 


We cannot "see" your C Drive!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top