Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to exit a VB6 program returning an errorlevel to MS-DOS

Status
Not open for further replies.

jajest

IS-IT--Management
Nov 6, 2003
28
BE

can somebody explain me how to end a VB6 program and set the value for errorlevel ? this is a value that a program returns when it was called from a DOS prompt.

I want to be able to set this value before exiting my program.

thanx.


 
API call

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

' Exit with ErrorLevel set to 9
ExitProcess 9



Not sure of all ramifications myself so use at own risk.
 
doesn't work.

the only things that happens is that my application exits at the command but no errorlevel is given.

 
Hmm.

It works for me. I've been using this method for years. What, precisely, are you expecting to happen?
 
Me too, post what you are trying to with the errorlevel maybe?
 
Ok, here it comes:

let's keep it simple:

the project consists of 1 module (module1.bas) and no forms.
the name of the project is LOKCHECK. The executable will be LOKCHECK.exe

the module looks like this:

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

Sub Main()
a = 5
ExitProcess (a)
End Sub


I know this looks stupid and makes no sense. It is only an example to help me to explain to you guys how I do it.

In fact, the exitcode that I want to return will depend on a condition that has nothing to dowith the problem here.

So, what do I do. I compiled a LOKCHECK.EXE. I open DOS box in W2K. I type 'LOKCHECK'. the program executes and returns to the DOs prompt. Then I type 'echo %errorlevel%'
I thought to see 5 as a result but it always shows 0.


Ps: the strange thing is when I'm running this program in the VB6 editor and press the RUN button, not only the program exits but also my VB6 itself also...
 
>I thought to see 5

Ah, but you thought wrong. This will only work if both the commands are in a batch file

>not only the program exits but also my VB6 itself also...

It would do. The owning process for a VB program in the IDE is the IDE itself. So, when you ExitProcess, you terminate the IDE
 

TO StrongM:

you're right! it works.

the problem was that I was testing this thing in DOS box interactive mode, not through a batch-file.

thanks for the help.


Marc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top