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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting app return codes from VB

Status
Not open for further replies.

CybOrg

Programmer
Nov 30, 1998
57
SE
Hi!

I tried setting different return codes in my VB app (so I can take appropriate actions when/if it fails), and I tried using the SetLastError function, but the app still seems to return 0, regardless of what happens... Clues, anyone?

/Cy
 
I haven't had any problems with it. Forgive me for stating the obvious but if your error codes aren't defined in scope you could have this problem, and you aren't trying to retrieve the error in a seperate thread are you? Or you're not trying to shell to it are you?
 
The whole picture is this:
I wish to run a sequence of programs in batch mode - producing reports, aggregating data and so forth. Some of these programs are dependent on the successful execution of a previous one. So let's say program 1:s task is to establish contact with a remote server and process some files. Program 2 aggregates the data from the remote server with data on a local machine and produces a report. If program 1 fails I don't want to run program 2... So I've got this Batch scheduler that can start apps and check for return codes - all I need to do is issue the codes. I read something about setting bit 29 but I didn't understand...
/Cy
 
It'd be nice if there was a built-in way of doing this, but in their wisdom Microsft seem to have left out the ability to return an exit code from a VB application. There is a workaround, however. Here is an example of a VB function that will exit an application with an exit code that you can chack with ERRORLEVEL (be warned that it terminates a VB program somewhat rudely; you should ensure that you have done whatever cleaning up is done before calling it. Additionally, don't call it from the IDE, since it will shut down both the application and the VB development environment):

Option Explicit
Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)

Private Sub ExitWithError(lErrorCode As Long)
ExitThread lErrorCode
End Sub

 
Hi again!

I tried almost that - I used ExitProcess instead, and it does seem to do the trick. I'm worried about what's left in memory, though - does that function unload all forms and modules read into memory, for instance? (If you're interested in what batch scheduler I'm using, by the way, I'll be happy to plug for it, only not in this forum... ;-))

/Cy
 
One of the things cited as "new" for VB.Net is the ability to write "console programs" - which is what you seem to be trying to do here.

If these are "batch" programs then there isn't any user interface right? As in "unattended" being checked. Which implies no user-interface event processing.

If so, how do you handle other event processing? Are you doing something like waiting around in Form_Load on a DoEvents loop or something, exiting the loop (and the program) when something in an event handler changes your loop-control variable from False to True?
 
I have a number of apps that can run unattended (in theory) - they collect statistics from other systems and produce reports, among other things. I also have an app that runs once an hour to generate fresh statistics for a customer accessible web site. There are a number of things that can go wrong during the collection process, and what I've done now is generate my own error codes, calling ExitProcess with them.
My batch scheduler (off-the-shelf) traps the error codes and reacts to them, sending messages or triggering other jobs or preventing subsequent jobs from being run. Kinda like JCC7 on the mainframe...
I tried to run the jobs unattended, but not seeing them on the screen made me too nervous - our company suffers unacceptable badwill if the jobs don't run, and I don't really trust ANY PC software in a Windows environment... :-(

/Cy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top