Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Jun 24, 2000

Terminate the process with an ErrorLevel code

If your VB application is meant to be called from within a Ms-Dos batch file, you must be able to return Dos an error code. This can be accomplished using the ExitProcess API function:

Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

' terminate the program and return ErrorLevel = 3
ExitProcess 3
Note that the ExitProcess API function is similar to the END command, in that it prevents all the usual clean up code from executing. Therefore, you must call it only after you've manually closed all forms, files and databases, released all memory and resources allocated through Windows, etc.

The following Ms-Dos batch program demonstrates how you can test the ErrorLevel returned by the VB application


START /W project1
REM ErrorLevel codes must be tested in reverse order
IF ERRORLEVEL 5 GOTO Err5
IF ERRORLEVEL 4 GOTO Err4
IF ERRORLEVEL 3 GOTO Err3
IF ERRORLEVEL 2 GOTO Err2
IF ERRORLEVEL 1 GOTO Err1

ECHO ErrorLevel = 0 
GOTO Exit
:Err1
ECHO ErrorLevel = 1
GOTO Exit
:Err2
ECHO ErrorLevel = 2
GOTO Exit
:Err3
ECHO ErrorLevel = 3
GOTO Exit
:Err4
ECHO ErrorLevel = 4
GOTO Exit
:Err5
ECHO ErrorLevel = 5

:Exit
REM End of batch file

Note that you must use the syntax START /W if you're running under Windows 95.
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date