UserCancelled Function

Used to determine if the user has pressed Escape (on Windows or Linux) or Command-period (on Macintosh) or to cancel the execution of code.

Syntax
result = UserCancelled( )

Return Value
Result | Boolean | Result is True if the user has pressed Escape (on Windows or Linux) or Command-period (on Macintosh) or and False if the user did not cancel.

# Notes

The UserCancelled function will continue to return True until the event handler that was executing when the user pressed Escape or Command-period is finished.

If you use the DoEvents method of the Application class to yield time back to REALbasic within a loop, then the UserCancelled function does not work.

If you need the equivalent functionality when you use DoEvents, then you should check the Async key state of the keyboard using the methods of the Keyboard object to see if the proper combination has been hit. However, these two concepts are typically exclusive. You use DoEvents when you want to update the user interface while executing a loop. This gives the user a way stop the loop by clicking a button or some other interface item. You use UserCancelled when you're in a tight loop with no user interface element to click on.

# Examples

This example uses the UserCancelled function to exit a For loop if the user presses Command-period/Escape.

Dim i As Integer
For i = 0 to 10000
ProgressBar1.Value = i
If UserCancelled Then
Exit
End If
Next

# See Also

Exit, Do...Loop, For...Next, While...Wend statements; Application class.