It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

if statement is ignored???

Moderator: dafunkymunky

if statement is ignored???

Postby SFCHTM on Tue Nov 17, 2009 3:11 pm

I'm in Reflection for UNIX and OpenVMS on a Windows XP system. I've gone around and around and can't figure out why the if statement is ignored when I run this macro. It goes through the array without a problem unless the Yes// comes up. Then it just halts. All I want it to do is enter two times at the Yes// Prompt. I can CR manually and the macro with continue to run it is as if the if statement does not exist. Any suggestions?

Code: Select all
Sub Test()

    Const NEVER_TIME_OUT = 0

    Dim CR As String ' Chr$(rcCR) = Chr$(13) = Control-M
    Dim myArray(3)
   
    myArray(0) = "1"
    myArray(1) = "2"
    myArray(2) = "3"
    myArray(3) = "4"
   
    CR = Chr(Reflection2.ControlCodes.rcCR)

    With Session

For i = 0 To 3

    Do While Not .WaitForString("Select:", NEVER_TIME_OUT, rcAllowKeystrokes)

   If .WaitForString("Yes//", NEVER_TIME_OUT, rcAllowKeystrokes) Then
   .Transmit CR
   .Transmit CR
   Exit Do
   End If
    Loop

    .Transmit myArray(i)
    .Transmit CR
    Next

  End With
 
  End Sub
SFCHTM
 
Posts: 1
Joined: Tue Nov 17, 2009 2:53 pm

Re: if statement is ignored???

Postby glenngarson on Fri Sep 10, 2010 5:40 pm

Here is a Case/Select that is more general than an 'if', you can use an 'if' if you like, just change the code

I tried to put the important pieces down here to help you check the response back from the terminal, and process the response.

Basically: section 4] shows you where the problem would occur, then section 5] and 6] provide two solutions for processing responses back from the terminal

I may have forgotten some pieces....good luck


' 1] Reference: COM => 'Reflection for UNIX and OpenVMS' 2.0

'2]
Dim _sessReflection As Reflection2.Session

'3]
_sessReflection = CreateObject("Reflection2.Session")
' Global variable;
Friend g_bStop_VISTA_Loop As Boolean = False
'False => keep doing whatever you are doing, True => STOP waiting for VISTA and leave what you are doing.

'4] Sample section of code that is waiting for response back from terminal

.TransmitTerminalKey(rcVtEnterKey)
.StatusBar = "whatever"

' {This one uses a Case Select to determine course of action}
CheckingForString_ProceedWhenFound_CaseSelect(_sessReflection, 1000)

'{This one waits for a specific string on cursor's line before proceding}
CheckingForString_ProceedWhenFound("PAYMENT AMOUNT:",_sessReflection)

'5] First subroutine: Case/Select
'====================================================================
Friend Sub CheckingForString_ProceedWhenFound_CaseSelect1(ByRef sessX As Reflection2.Session, ByVal iMaxTrys As Integer)

'a) Keep checking the string until the condition is figured out (up to iMaxTrys trys)
' If the condition is not determined then: a) set g_bStop_VISTA_Loop = TRUE, and send up a message box
'b) Based on the condition Send something to the terminal
'c) Interate, i.e. recall the routine

Dim sCursorText As String
Dim sRightMost As String
Dim bLeaveTheLoopAndProceedProcessingTheString As Boolean = False
Dim iCounter As Integer = 0
Dim bTryAgain As Boolean = True


Do While ((bLeaveTheLoopAndProceedProcessingTheString = False) And (g_bStop_VISTA_Loop = False) And (iCounter < iMaxTrys))
With sessX

sCursorText = Trim(.GetText(.CursorRow, 0, .CursorRow, .DisplayColumns))

Select Case sCursorText
Case "Do you want to continue processing this patient record? No//"
'Situation #1
.Transmit("y")
.TransmitTerminalKey(rcVtEnterKey)
DebugPrint("= RESOLVED = = => SENSITIVE Veteran Info <= = = = = = = = ")
bLeaveTheLoopAndProceedProcessingTheString = True
bTryAgain = True

Case "Are you sure you wish to continue (Y/N)?"
'Situation #2
.Transmit("y")
.TransmitTerminalKey(rcVtEnterKey)
DebugPrint("= RESOLVED = = => Same Name or Same Last 4 of SSN <= = = = = = = = ")
bLeaveTheLoopAndProceedProcessingTheString = True
bTryAgain = True

Case Else
DebugPrint(CStr(iCounter) & "] =====================================================")
DebugPrint(CStr(iCounter) & "] Found @ Cursor (sCursorText) : " & "[" & sCursorText & "] <==========")

End Select

System.Windows.Forms.Application.DoEvents()
End With
iCounter = iCounter + 1
Delay(k_DelayInSeconds_WaitingForVISTA)
Loop 'While Loop

If ((bTryAgain = True) And (iCounter < iMaxTrys)) Then
CheckingForString_ProceedWhenFound_AA1_1(sessX, iMaxTrys)
Else
'Done and ready to continue processing
End If


End Sub
'====================================================================

'6 Second Subroutine:
'====================================================================
Friend Sub CheckingForString_ProceedWhenFound(ByVal sTextToWaitFor As String, ByRef sessX As Reflection2.Session)

Dim sCursorText As String
Dim sRightMost As String
Dim bLeaveTheLoopAndProceedProcessingTheData As Boolean = False
Dim iCounter As Integer = 0
Dim iNumberOfCharactersToCheck As Integer = Len(sTextToWaitFor)

DebugPrint("START ************* *************** CheckingForString_ProceedWhenFound *********** ************")
DebugPrint("iNumberOfCharactersToCheck: " & CStr(iNumberOfCharactersToCheck))
DebugPrint("")

Do While ((bLeaveTheLoopAndProceedProcessingTheData = False) And (g_bStop_VISTA_Loop = False) And (iCounter < 1000))
With sessX
sCursorText = Trim(.GetText(.CursorRow, 0, .CursorRow, .DisplayColumns))
Debug.Print(CStr(iCounter) & "] =====================================================")

DebugPrint(CStr(iCounter) & "] Found @ Cursor (sCursorText) : " & "[" & sCursorText & "] <==========")
DebugPrint(CStr(iCounter) & "] ==========> Looking For @ Cursor: " & "[" & sTextToWaitFor & "]")
DebugPrint("")

sRightMost = Right(sCursorText, iNumberOfCharactersToCheck)
DebugPrint("Right most characters at the cursor: [" & sRightMost & "]")

If sTextToWaitFor = sRightMost Then bLeaveTheLoopAndProceedProcessingTheData = True


DebugPrint(" bLeaveTheLoopAndProceedProcessingTheData: " & CStr(bLeaveTheLoopAndProceedProcessingTheData))
DebugPrint(" g_bStop_VISTA_Loop: " & CStr(g_bStop_VISTA_Loop))
DebugPrint("")
System.Windows.Forms.Application.DoEvents()

End With
iCounter = iCounter + 1
Delay(k_DelayInSeconds_WaitingForVISTA)
Loop


End Sub
'====================================================================

'7] Usefull sub

'====================================================================
' Subroutine used for delays {Got this off the internet}

Friend Sub Delay(ByVal DelayInSeconds As Double)
Dim ts As TimeSpan
Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)
Do
ts = targetTime.Subtract(DateTime.Now)
Application.DoEvents() ' keep app responsive
System.Threading.Thread.Sleep(50) ' reduce CPU usage
Loop While ts.TotalSeconds > 0
End Sub
'====================================================================

''8 ] Another Usefull sub

'====================================================================
Friend Sub DebugPrint(ByVal sX As String)

If k_DebugModeOn Then
Debug.Print(sX)
End If


End Sub
'====================================================================
glenngarson
 
Posts: 2
Joined: Fri Sep 10, 2010 4:59 pm

Re: if statement is ignored???

Postby glenngarson on Fri Sep 10, 2010 5:46 pm

Woops, I cut too much out of the Case/Select statement before I posted it. Here is a key case that needs to be in the Case/Selet. It is the one that lets you out of the loop:

'======================================
Case "PAYMENT AMOUNT:"
' this is the response for Parm 3, so drop out of the subroutine
DebugPrint("= RESOLVED = = => PAYMENT AMOUNT: <= = = = = = = = ")
DebugPrint("= RESOLVED = = => Ready to process Parm 2 <= = = = = = = = ")
bLeaveTheLoopAndProceedProcessingTheString = True
bTryAgain = False

'======================================

good luck
glenngarson
 
Posts: 2
Joined: Fri Sep 10, 2010 4:59 pm


Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests