Solved

Visual Basic Exit Codes

Posted on 1997-06-24
6
744 Views
Last Modified: 2013-11-25
We are starting a VB application from an existing application that checks for exit codes.

With C we can do "exit(3)" and such, but no such thing exists natively for VB.

We've tried ExitProcess(), but it doesn't seem to work.

Is there another system call or approach that works?
0
Comment
Question by:klamerus
6 Comments
 
LVL 7

Expert Comment

by:tward
ID: 1427649
Try the following API Calls (32bit ONLY):

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

Declare Sub ExitThread Lib "kernel32" Alias "ExitThread" (ByVal dwExitCode As Long)

0
 
LVL 1

Author Comment

by:klamerus
ID: 1427650
Edited text of question
0
 
LVL 1

Author Comment

by:klamerus
ID: 1427651
We've tried that approach and it doesn't work or we're doing it incorrectly.  I mentioned that the above procedure hasn't been working in the original question.

If you can provide an example of a *.bat file which shows this to work, I'd appreciate it, but for now I'm assuming that it doesn't.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Expert Comment

by:pdove
ID: 1427652
Dan Appleman, in his 'Visual Basic 5.0 Programmers Guide to the Win32 API' writes this about ExitProcess...'You should avoid trying to close processes using this function.  Do not use on your own VB applications.  Instead, try posting a WM_CLOSE message to the main window of the application you want to close.'That probably doesn't help you a lot, but may help explain why it is not working for you. :)  I wish you luck and will certainly look at any answer you get.
0
 
LVL 3

Accepted Solution

by:
ChrisLewis earned 100 total points
ID: 1427653
I don't believe that VB will support an exit code.  The problem is that VB programs aren't in the same format as C programs, they kinda sorta run under the VB runtime environment.  So ExitProcess doesn't really work with VB.

The other thing that you are mentioning is returning the exit code to a DOS batch file (for an IF ERRORLEVEL perhaps...)  .  I don't think windows programs can do this at all.  Dos is Dos and Windows is Windows, and the two really can't talk using exit codes.

Sorry,

Chris
0
 
LVL 1

Author Comment

by:klamerus
ID: 1427654
Exit Process is a Win32 call - it works to the extent that it kills the Visual Basic Process.  It should work the rest of the way.
So should TerminateProcess work to kill other processes (and it does).

Perhaps what I need is a better test process than a DOS batch utility.  Or perhaps (since the program calling my program is a DOS utility), what I need is a way to return values to DOS.

As to not getting a return code from a DOS shell - that makes sense.  It is hard to see how a DOS app would be able to evaluate information from the Windows environment.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question