Key Concepts > Handling Asynchronous Behavior |
When your macro interacts with a mainframe program, you'll need to handle the asynchronous behavior that occurs between your macro and the host program.
Your macro runs independently of the host program. Two programs are processsing commands (the host program and your macro) and these programs are not synchronized. Because of this asyncronous behaviour, you'll need to pause execution of your macro after you send a command to the host. After the host responds and InfoConnect processes the data to render a new screen, you can resume execution. If your macro tries to interact with the screen before it is ready, it will get unexpected results or errors.
To handle this asychronous behaviour and make sure your macro waits until the terminal screens or Web pages are ready, use the following InfoConnect events and methods.
For IBM programs, use the NewScreenReady event to handle asynchronous behaviour.
Using the NewScreenReady Event |
Copy Code
|
---|---|
Private Sub IbmScreen_NewScreenReady(ByVal sender As Variant) 'Set the Screen ID variables used to identify which screen is active. Dim ScreenID1 As String Dim ScreenID2 As String Dim retVal As ReturnCode 'Get values for the screen IDs every time a screen loads. ScreenID1 = Trim(ThisIbmScreen.GetText(1, 2, 3)) ScreenID2 = Trim(ThisIbmScreen.GetText(1, 1, 5)) 'Compare the ScreenID values with known values to determine which screen is active. If ScreenID1 = "ATM" Then 'Send command to host ThisIbmScreen.SendControlKey (ControlKeyCode_Transmit) ElseIf ScreenID2 = "LOGON" Or ScreenID2 = "Ready" Then 'Send data to host ThisIbmScreen.SendKeys ("ISPF") 'Send command to host ThisIbmScreen.SendControlKey (ControlKeyCode_Transmit) End If End Sub |
To set up your macro, record it and navigate through the screens you need to use. Then look at the recorded macro to find the strings that the WaitForString method is waiting for. In this example, we'll use the WaitForString3 method to wait for a screen in the InfoConnect demo to settle after we send a command.
To set up your macro to wait for the host reply
Get the strings to wait for |
Copy Code
|
---|---|
'Wait for a string on the host screen before continuing returnValue = osCurrentScreen.WaitForString3(LF & "Command> ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes) |
Using WaitForString3 |
Copy Code
|
---|---|
Dim returnValue As Integer Const NEVER_TIME_OUT = 0 ThisScreen.SendKeys "demodata" ThisScreen.SendControlKey ControlKeyCode_Return 'Wait for a string on the host screen before continuing returnValue = osCurrentScreen.WaitForString3(LF & "Command> ", NEVER_TIME_OUT, WaitForOption.WaitForOption_AllowKeystrokes) 'Continue with commands |
For Web documents, you can use the DocumentCompleted event to handle aynchronous behaviour.
Using the DocumentCompleted event |
Copy Code
|
---|---|
Private Sub WebControl_DocumentCompleted(ByVal sender As Variant, ByVal Url As String) Dim wElementValue As WebElement Dim wElementArray() As WebElement 'Get the heading text of the page wElementArray = ThisWebControl.Document.GetElementsByTagName("h1") 'Search the heading text to find out if the browser is on the page with the form If InStr(1, wElementArray(0).InnerHtml, "download instructions") > 0 Then 'If on the page with the form, put an email in the Email form field Set wElementValue = ThisWebControl.Document.GetElementById("emailAddress") wElementValue.PutText ("customer@xyz.com") End If End Sub |