by 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
'====================================================================