QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The _EXIT function prevents the user from closing a program and indicates if a user has clicked the close button in the window title (X button) or used CTRL + BREAK.

Syntax

exitSignal% = _EXIT

Description

Example(s)

Using an ON TIMER check to read the _EXIT request return values.


q = _EXIT 'function read prevents any program exit at start of program
ON TIMER(5) GOSUB quit
TIMER ON
PRINT "  The Timer will check for exit request every 5 seconds."
PRINT "Click the X box and/or Ctrl - Break to see the _EXIT return!"
PRINT "                    Any Key Quits"
PRINT
DO: _LIMIT 30
  '                    ' simulated program loop
LOOP UNTIL INKEY$ <> ""
END

quit:
q = _EXIT
IF q THEN PRINT q;
SELECT CASE q
  CASE 1: PRINT "= X button was clicked"
  CASE 2: PRINT "= Ctrl + Break keypress"
  CASE 3: PRINT "= Both X and Ctrl + Break!"
END SELECT
RETURN 

Removing temporary files before closing a program upon a user’s exit request.


x = _EXIT  'initial function call blocks a user exit
OPEN "t3mpdata.tmp" FOR APPEND AS #1
DO
IF _EXIT THEN CLOSE: KILL "t3mpdata.tmp": _DELAY 1: SYSTEM
LOOP 

Note: If you have a file named t3mpdata.tmp change the file name!

See Also