Microsoft KB Archive/178357

{|
 * width="100%"|

HOWTO: Set an Error Level from a Visual Basic Application

 * }

Q178357

-

The information in this article applies to:


 * Microsoft Visual Basic Professional Edition, 32-bit, for Windows, versions 4.0, 5.0, 6.0
 * Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, versions 4.0, 5.0, 6.0

-

SUMMARY
This article contains a sample Visual Basic application that sets the error level upon exiting and a DOS batch file to test the result. Visual Basic applications can also retrieve the error level returned by another Windows application using the technique shown in Q129796 listed below.

Steps to Reproduce Behavior

 * 1) Create a new Standard EXE project. Form1 is created by default.
 * 2) Place three CommandButtons on the form (use the default names).
 * 3) Add the following code to the General Declarations section of Form1:
 * 4) Save your Project and Make an executable named Project1.EXE.
 * 5) Create the following batch file named errlevel.bat in your project directory:
 * 6) Run the batch file. When the user clicks on a CommandButton, the application will terminate with the error level shown on the button. The batch file will then test the error level and echo the result to the screen.

Additional notes:

Start /w is necessary for this to work correctly in Windows 95.

"if errorlevel" must be in the order presented. "If the EXIT status is less than the specified value, the specified DOS command is executed; otherwise, processing continues with the next batch file command."

In order to retrieve the error level from a Visual Basic Program instead of a DOS Batch file:


 * Implement Knowledge Base article Q129796. Modify the call to ExecCmd function in the Form_Click event to pass "project1.exe" instead of "notepad.exe". Run the project and click on form1 to launch project1.exe.