Solved

Visual Basic Exit Codes

Posted on 1997-06-24
6
743 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 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