END terminator

Purpose: END immediately terminates a running program. END can be used in multiple places in your program.


Syntax:

 END [= ErrorLevel AS INTEGER]

Parameters:

  • Data type: INTEGER
    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 problem that caused the abnormal exit.

For example, this program, GetKey.bas, 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! Would you like to 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! Would you like to 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

END PROGRAM terminator


Syntax:

 END PROGRAM

Purpose: Intended for console mode programs, END PROGRAM forces the end of the main() function.

Remarks:

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.

An Example:


 ' Shows how BCX can use "C" functions directly 
 
 $HEADER
 CHAR * Remove_All_White_Space(CHAR *);
 $HEADER
 
 DIM a$
 DIM b$
 
 a$ = "     this   is    a     test      "
 
 b$ = Remove_All_White_Space(a$)
 
 PRINT b$
 
 END PROGRAM
 
 ! CHAR* Remove_All_White_Space(CHAR* str1)
 ! {
 !  CHAR *obuf,*nbuf;
 !  if (str1)
 !   {
 !    for (obuf=str1,nbuf=str1;*obuf;++obuf)
 !     {
 !      if (!isspace(*obuf))
 !      *nbuf++=*obuf;
 !     }
 !   *nbuf=0;
 !   }
 !  return str1;
 ! }