ONSTART prefix
Purpose: The ONSTART prefix specifies that the subroutine, which it prefixes, be called before any other procedure. Passing arguments to an ONSTART subroutine is not allowed.
Syntax: ONSTART SUB SubName() ' do something before your code executes END SUB Parameters:
|
ONEXIT prefix
Purpose: The ONEXIT prefix specifies that the subroutine, which it prefixes, be called after all other procedures. Passing arguments to an ONEXIT subroutine is not allowed.
Syntax: ONEXIT SUB SubName1() ' do something as your program exits back to OS END SUB Parameters:
|
Example 1:
? "This is a test of ONSTART and ONEXIT subroutines." ? "Notice that you don't have to explicitly call them?" ? "Also notice that ONSTART is called before any other" ? "code in your program and ONEXIT is called just before" ? "your program exits." ? "Both must be subs and neither may have any parameters." ? "These can be used to do initialing or cleanup code in" ? "your programs." ONSTART SUB XRay() ? "" ? "Hello !" ? "" END SUB ONEXIT SUB ZRay() ? "" ? "Goodbye ..." ? "" END SUB
Example 2:
PRINT "Hello there!" PAUSE ONSTART SUB first() PRINT "Starting!" END SUB ONSTART SUB second() PRINT "Starting 2!" END SUB ONEXIT SUB myexit() PRINT "Goodbye !" END SUB