EnableRuntimeError

Enables or disables run-time errors when a FlexScreen wait times out or SendKeys fails. Default is True (enabled).


It applies to WaitForCursor, WaitForCursorColumn, WaitForNoX, WaitForString, WaitForStringReceived, SendKeys, and WaitForHostUpdate when its EnableTimeoutError parameter is omitted.


Syntax

FlexScreen.EnableRuntimeError


FlexScreen.EnableRuntimeError = Boolean


Remarks
When EnableRuntimeError is True:

  • A wait that times out raises run-time error &H80131505, "Function 'name' timed out after n ms."
  • A wait on a session that is not connected raises run-time error &H80131320, "The session is not connected."
  • A SendKeys that fails raises run-time error &H80131500, "Function 'SendKeys' has failed."Unless the macro handles the error, it stops.


When EnableRuntimeError is False, the function returns False instead, and no error is raised.


Set EnableRuntimeError to False when the macro tests the return value of a wait, especially in a conditional statement. With On Error Resume Next in effect and EnableRuntimeError True, a timeout inside an If condition does not make the condition False. Execution resumes at the next statement, which is inside the If block, so the code for the True case runs.


Tip: under On Error Resume Next, when a call raises an error, the rest of that line is skipped. Check Err.Number on a line of its own:


Sub Main()

   On Error Resume Next

   Ok = FlexScreen.WaitForString("Ready", FlexScreen.Position(1, 1))

   If Err.Number <> 0 Then MsgBox "Error " & Hex(Err.Number) & ": " & Err.Description

End Sub


Example

The following example sets EnableRuntimeError to False. If it were True, a timeout would make the macro show "Text found!" even though the text was not found.


Sub Main()

   On Error Resume Next

   FlexScreen.EnableRuntimeError = False

   If FlexScreen.WaitForString("Userid1", FlexScreen.Position(10, 11)) = True Then

      MsgBox "Text found!"

   Else

      MsgBox "Text Not Found!"

   End If

End Sub