'=========================================================================== ' Subject: PROGRAM ERRORLEVELS Date: 06-16-96 (00:00) ' Author: Christy Gemmell Code: QB, PDS ' Origin: FidoNet QUIK_BAS Echo Packet: DOS.ABC '=========================================================================== ' ======================================================================== 'How about exiting your program with an ErrorLevel to give to DOS. 'Useful for use in batch files using "IF ERRORLEVEL n GOTO label" 'WARNING: Do not use this whilst in the QuickBASIC environment, as 'all hell will break loose. You will loose your program and maybe 'even lose other data too - You have been warned !!! 'Here is the Declare...put it in your main module: DECLARE SUB ExitWithErrLvl ALIAS "_exit" (BYVAL errorlevel%) 'Now some sample code to show how to use it: 'This example will exit setting ErrorLevel to 3. VarE% = 3 PRINT "Exiting with errorlevel";VarE% ExitWithErrLvl VarE% ' ----------------------------------------------------------------------- 'How about Shelling out to, and running, another program and then 'obtaining the ErrorLevel returned from that SHELL'd program? 'NEWSHELL.FUN an alternative to the shell command which returns an ' 'ERRORLEVEL code. ' 'Author: Dave Navarro 'For: PowerBASIC 'Date: 16/6/1995 'Adapted for QuickBASIC by Christy Gemmell 'You must $INCLUDE: 'QB.BI' at the top of your main program and 'LINK the executable with QB.LIB (or load QB.QLB into the IDE). '$INCLUDE: 'QB.BI' DECLARE FUNCTION MyShell% (Program$, Parameters$) ' Enter the *full* Program Name here (eg. XCOPY.EXE) Program$ = "XCOPY.EXE" ' Enter any parameters (command line switches) here Parameters$ = "*.* A:" PRINT MyShell%(Program$, Parameters$) FUNCTION MyShell% (Program$, Parameters$) DIM Regs AS RegType ' For use with CALL INTERRUPT Path$ = ENVIRON$("PATH") ' Save PATH Comspec$ = ENVIRON$("COMSPEC") ' Save COMSPEC ENVIRON "PATH=" ' Temporarily remove the path ENVIRON "COMSPEC=" + Program$ ' Set COMSPEC to our program SHELL Parameters$ ' Execute the program ENVIRON "COMSPEC=" + Comspec$ ' Restore the comspec ENVIRON "PATH=" + Path$ ' Restore the path Regs.ax = &H4D00 ' DOS service 77 INTERRUPT &H21, Regs, Regs ' - get ERRORLEVEL code MyShell% = Regs.ax AND &HFF ' Return exit code END FUNCTION ' ------------------------------------------------------------------------