From Xojo Documentation

Revision as of 19:00, 19 November 2009 by WikiSysop (talk) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!


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.



Part Type Description
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.


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 module 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.


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

For i = 0 to 10000
 ProgressBar1.Value = i
If UserCancelled Then

See Also

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