END

Purpose: Immediately terminates a running program. END can be used multiple times in your program.


 Syntax 1:

 END [= ErrorLevel%]

 Parameters:

  • ErrorLevel% [OPTIONAL] integer literal or variable containing value to be returned by program. The default errorlevel returned for a program exiting normally is 0. If the OPTIONAL ErrorLevel is used then the value specified will be returned as the errorlevel by the program. An abnormal exit will result in a number other than 0 to be returned. The value of this number can help determine the cause of the problem that caused the abnormal exit.

For example, this program, getkey, returns the key pressed as an errorlevel


 DIM ErrorLevel%
 
 DO
   ErrorLevel% = INKEY
 LOOP WHILE ErrorLevel% = 0
 END = ErrorLevel%

In the batch file example below getkey is used to get a response based on an errorlevel from the hypothetical myprog program.


 :begin
 myprog.exe
 if errorlevel = 0 goto done
 if errorlevel = 1 goto noinit
 if errorlevel = 2 goto baddata
 echo unknown error
 goto done
 :baddata
 echo Data was corrupt Use Backup Data Y/N
 getkey.exe
 if errorlevel = 89 goto olddata
 if errorlevel = 121 goto olddata
 if errorlevel = 78 goto done
 if errorlevel = 110 goto done
 goto baddata
 :olddata
 copy backup\myprog.dat myprog.dat
 goto begin

 :noinit
 echo No Initialization File. Use Backup File Y/N
 getkey.exe
 if errorlevel = 89 goto reinit
 if errorlevel = 121 goto reinit
 if errorlevel = 78 goto done
 if errorlevel = 110 goto done
 goto noinit
 :reinit
 copy backup\myprog.ini myprog.ini
 goto begin

 :done


 Syntax 2:

 END PROGRAM

Purpose: Intended for console mode programs, END PROGRAM forces the end of the main() function. This is particularly handy when you want to include blocks of "C" code outside of the main function. END PROGRAM must be used only once in your program.

Remarks:

An Example:


 C_DECLARE SUB SayGoodNightGracy()

 PRINT "Hello, World!"
 SayGoodNightGracy()

 END PROGRAM

 ! extern void SayGoodNightGracy()
 !
 ! printf("%s","Good Night Gracy!");
 !