Option Explicit Global AttachSess0 As Object Global AttachSys As Object Global AttachSessions As Object Public Function OpenAttachMate(Optional session As String = "A") As Object Rem: ********************************************************************************************** Rem: * This Sub Opens An AttachMate Session * Rem: ********************************************************************************************** On Error GoTo error_handler Rem: Initialiaze And Start Up Attachmate Rem: ------------------------------------- If AttachSys Is Nothing Then Set AttachSys = CreateObject("EXTRA.System") Set AttachSessions = AttachSys.Sessions End If Rem: Start up the session and Make Attachmate Visible Rem: ------------------------------------------------- Set OpenAttachMate = GetObject("Y:\My Documents\AttachMate\EXTRA!\sessions\EOC Session " & session & ".edp") OpenAttachMate.Visible = True Rem: Wait For 10 Seconds Rem: -------------------- Dim strTime As String strTime = Now + TimeValue("0:00:10") Do While (CDate(strTime) > CDate(Now)) 'and we wait for 10 seconds ;) Loop OpenAttachMate.Visible = True If OpenAttachMate.Screen.GetString(1, 2, 21) <> "ENTER APPLICATION ==>" Then WriteToLogfile ("AttachMate Session " & session & " is already open. Please close your AttachMate session and try again.") Exit Function End If Exit Function error_handler: ErrorHandler "OpenAttachMate", "M_AttachMate", Err.Number, Err.Description, Erl MsgBox "Please contact EB - Tactical Tool Desk!", vbInformation, "A Problem Occured" End End Function Public Sub LoginAttachMate(User_id As String, Password As String, Optional AttachSess As Object) Rem: ********************************************************************************************** Rem: * This Sub opens An AttachMate Session * Rem: ********************************************************************************************** If AttachSess Is Nothing Then Set AttachSess = AttachSess0 End If On Error GoTo error_handler Rem: Fill in "CICSP" Rem: ---------------- AttachSess.Screen.putstring "CICSP", 1, 24 SubmitAndWait max_ms:=3000 Rem: Fill In The User ID Rem: --------------------- AttachSess.Screen.putstring strUsername, 19, 42 Rem: Fill In The User Password Rem: -------------------------- AttachSess.Screen.putstring strPassword, 20, 42 SubmitAndWait max_ms:=1500 Exit Sub error_handler: MsgBox "Please contact EB - Tactical Tool Desk!", vbInformation, "A Problem Occured" ErrorHandler "LoginAttachMate", "M_AttachMate", Err.Number, Err.Description, Erl End End Sub Public Sub WaitForClockStatus(Optional max_ms As Long = 2500, Optional AttachSess As Object) Rem: Error Handling Rem: --------------- If AttachSess Is Nothing Then Set AttachSess = AttachSess0 End If On Error GoTo error_handler Dim ms As Long For ms = 0 To max_ms Step 50 If AttachSess.Screen.OIA.XStatus = 0 Then Exit Sub End If AttachSess.Screen.WaitHostQuiet (50) Next #If ForceDebug Then Select Case MsgBox("Press [Yes] to debug, [No] to proceed and [Cancel] to quit.", vbYesNoCancel, "Clock did not disappear after " & CStr(max_ms) & " miliseconds") Case vbYes Debug.Assert False Case vbNo Exit Sub Case vbCancel End End Select #Else Select Case MsgBox("Proceed anyway?", vbOKCancel, "Clock did not disappear after " & CStr(max_ms) & " miliseconds") Case vbOK Exit Sub Case vbCancel End End Select #End If Rem: Error Handling Rem: --------------- Exit Sub error_handler: MsgBox "Please contact EB - Tactical Tool Desk!", vbInformation, "A Problem Occured" ErrorHandler "WaitForClockStatus", "M_AttachMate", Err.Number, Err.Description, Erl End End Sub Public Sub WaitForScreen(expectedScreen As String, Optional max_ms As Long = 2500, Optional AttachSess As Object) Rem: Error Handling Rem: --------------- If AttachSess Is Nothing Then AttachSess = AttachSess0 End If On Error GoTo error_handler Dim ms As Long, currentScreen As String For ms = 0 To max_ms Step 50 currentScreen = Trim(Replace(AttachSess.Screen.GetString(1, 2, Len(expectedScreen) + 1), "=", "")) If currentScreen = expectedScreen Then Exit Sub End If AttachSess.Screen.WaitHostQuiet (50) Next #If ForceDebug Then Select Case MsgBox("Press [Yes] to debug, [No] to proceed and [Cancel] to quit.", vbYesNoCancel, expectedScreen & " did not appear after " & CStr(max_ms) & " miliseconds") Case vbYes Debug.Assert False Case vbNo Exit Sub Case vbCancel End End Select #Else Select Case MsgBox("Proceed anyway?", vbOKCancel, "Clock did not disappear after " & CStr(max_ms) & " miliseconds") Case vbOK Exit Sub Case vbCancel End End Select #End If Rem: Error Handling Rem: --------------- Exit Sub error_handler: MsgBox "Please contact EB - Tactical Tool Desk!", vbInformation, "A Problem Occured" ErrorHandler "WaitForScreen", "M_AttachMate", Err.Number, Err.Description, Erl End Sub Public Sub SubmitAndWait(Optional key2send As String = "", Optional expectedScreen As String = "", Optional min_ms As Long = 500, Optional max_ms As Long = 2500, Optional snapShot As Boolean = False, Optional AttachSess As Object) If AttachSess Is Nothing Then Set AttachSess = AttachSess0 End If #If ForceDebug Then Debug.Assert False 'Inspect before execution ' Horsten #End If If snapShot Then TakeScreenShot key2send:=key2send, expectedScreen:=expectedScreen End If AttachSess.Screen.SendKeys key2send '"" AttachSess.Screen.WaitHostQuiet (min_ms) If expectedScreen = "" Then WaitForClockStatus IIf(max_ms > min_ms, max_ms - min_ms, 0), AttachSess Else WaitForScreen expectedScreen, IIf(max_ms > min_ms, max_ms - min_ms, 0), AttachSess End If End Sub Public Sub PutField(text2put As String, rowPosition As Long, colPosition As Long, Optional caption As String = "", Optional AttachSess As Object) Dim leftOfField As String If AttachSess Is Nothing Then AttachSess = AttachSess0 End If If caption <> "" Then leftOfField = AttachSess.Screen.GetString(rowPosition, 1, colPosition - 1) #If ForceDebug Then Debug.Assert InStr(1, lefoffield, caption) > 0 #Else If InStr(1, leftOfField, caption) = 0 Then If vbCancel = MsgBox("Proceed anyway?", vbOKCancel, caption & " does not appear on line " & CStr(rowPosition)) Then End End If End If #End If End If If Trim(AttachSess.Screen.GetString(rowPosition, colPosition, 1)) <> "" Then AttachSess0.Screen.MoveTo rowPosition, colPosition SubmitAndWait key2send:="" End If AttachSess.Screen.putstring text2put, rowPosition, colPosition End Sub