Visual Basic - Technik, FAQ, Tricks, Beispiele

Home / System / Shell / ErrorLevel

Programm mit ErrorLevel beenden

Impressum
Kontakt
DSVGO
Soll ein VB-Programm aus einer Batch heraus aufgerufen werden, so wäre oft ein Rückgabewert in Form eines ErrorLevels nützlich. Die API-Funktion ExitProcess beendet ein Programm (analog zu End) und gibt eine Fehlernummer an die Shell zurück:
Declare Sub ExitProcess Lib "kernel32" ( _
    ByVal uExitCode As Long)

'Beispiel:
ExitProcess 2
Die folgende Batch zeigt, wie der Rückgabewert abgefangen kann:
START /W VBProgramm
IF ERRORLEVEL 3 GOTO Err3
IF ERRORLEVEL 2 GOTO Err2
IF ERRORLEVEL 1 GOTO Err1
ECHO Kein Wert
GOTO Exit
:Err1
ECHO Wert 1
GOTO Exit
:Err2
ECHO Wert 2
GOTO Exit
:Err3
ECHO Wert 3
GOTO Exit
:Exit

Übersetzung eines Artikels von Francesco Balena (VB2TheMax).

© Jost Schwider, 24.06.2000-24.06.2000 - http://vb-tec.de/errorlev.htm