The information in this article applies to:
- Microsoft Visual Basic Professional and Enterprise Editions for
Windows, versions 4.0, 5.0
on the following platforms: NT, Win95
SUMMARY
This article contains a sample Visual Basic application that sets the DOS
error level upon exiting and a DOS batch file for testing.
MORE INFORMATION
- Start a new project and save as Project1.
- In the Declaration Section of Form1, add the following declaration:
Private Declare Sub ExitProcess Lib "kernel32" _
(ByVal uExitCode As Long)
- Place three CommandButtons on the form (use default names).
- Change the Caption property on the CommandButtons to 50, 100, and 150
respectively.
- Place the following code behind the form:
Private Sub Command1_Click()
ExitProcess (50&) 'Button labeled "50"
End Sub
Private Sub Command2_Click()
ExitProcess (100&) 'Button labeled "100"
End Sub
Private Sub Command3_Click()
ExitProcess (150&) ''Button labeled "150"
End Sub
- Save the Project and Make the executable.
- Create the following batch file named errlevel.bat in your project
directory:
echo off
start /w project1
rem "start /w"
if errorlevel 150 goto 150
if errorlevel 100 goto 100
if errorlevel 50 goto 50
echo Exit Code 0
goto Done
:150
echo Exit Code 150
goto done
:100
echo Exit Code 100
goto done
:50
echo Exit Code 50
:done
echo done
- Run the batch file. When the user clicks on a CommandButton, the
application will terminate with the error level 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."
REFERENCES
MS-DOS Batch Files, Second edition, MS Press
Keywords : VB4WIN vb5all vb5howto
Version : WINDOWS:4.0,5.0
Platform : NT Win95 WINDOWS
Issue type : kbhowto
|