Exiting with a DOS Errorl

 BBS: Inland Empire Archive
Date: 01-31-93 (07:22)             Number: 325
From: NORMAN SCOTT                 Refer#: NONE
  To: ANNE BUSSELL                  Recvd: NO  
Subj: Exiting with a DOS Errorl      Conf: (2) Quik_Bas
Hi Anne!
On Friday January 29 1993 Anne Bussell said to All:

 AB> Is there anyway to force a QuickBASIC program to exit on a particular
 AB> DOS errorlevel???

Below is the pertinent parts of a program of how I do it.
My programs exit with a DOS errorlevel = QB errorcode, or
DOS errorlevel = program errorcode, or errorlevel of 0 if
no error occured.

DECLARE SUB ExitWithErrLvl ALIAS "_exit" (BYVAL ErrorLevel%)
'    Must be compiled as:  "QB/L QB"   <------------ * NOTE *
ON ERROR GOTO ErrorHandler
CmdParam$ = COMMAND$
IF LEN(CmdParam$) = 0 THEN
    TheCode% = 101: GOTO TheExit
.  [ Rest of the program here. ]
.  [ If a QB error occurs, program will go to label ErrorHandler: ]
.  [ Ending point of program *IF* everything worked! ]
TheCode% = 0                      ' Set errorlevel to "0"
ExitWithErrLvl TheCode%           ' Normal Program Termination.

ErrorHandler:                     ' Abnormal Program Termination.
TheCode% = ERR: RESUME TheExit
TheExit:                          ' Begin abnormal exit, QB or programmed
COLOR 14, 0: PRINT TAB(23); "Program Termination Error Code: ";
COLOR 15, 0: PRINT TheCode%
ErrorFile$ = Path2Cfg$ + ThisProg$ + ".ERR"  'Path2Cfg$ = environment var.
PRINT #9, "=== On "; DATE$; " @ "; TIME$
PRINT #9, ThisProg$; " Terminated w/ Error Code of"; TheCode%
ExitWithErrLvl TheCode%

     Happy BBS'in...                       Norman

--- GoldED 2.40+
 * Origin: Phoenix - Montgomery, AL (1:375/8)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET