Home All Groups Group Topic Archive Search About

setting exit code of VB app

Author
1 Jun 2005 7:59 PM
MB Blackburn
Hello,

My windows app developed in VB has a command line mode.
So I expect that other applications will call my app using a shell approach.
In the case of command line syntax errors, I want to exit with code that
indicates that nature of the error.
Is there a way to control the "exit code" the VB application "returns" when
it terminates?
Perhaps I must make a Win API call?

I have perused the VB help files but have not found anything pertinent.

tia,

MBB

Author
1 Jun 2005 8:14 PM
Karl E. Peterson
MB Blackburn wrote:
> My windows app developed in VB has a command line mode.
> So I expect that other applications will call my app using a shell
> approach. In the case of command line syntax errors, I want to exit
> with code that indicates that nature of the error.
> Is there a way to control the "exit code" the VB application
> "returns" when it terminates?
> Perhaps I must make a Win API call?

You'd use the ExitProcess API.  Lots of issues there, most of them covered for you by
the following two examples:

  http://vb.mvps.org/samples/Hello
  http://vb.mvps.org/samples/Console

The first is a windowed app, the second (obviously?) purely console (and far more
involved).  In short, I'd recommend you only call it from a native EXE, not in the
IDE or from pcode, and make sure it's the *last* thing you (intended to) do in the
app.
--
Working Without a .NET?
http://classicvb.org/petition
Author
1 Jun 2005 8:52 PM
MB Blackburn
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:e6J$5ZuZFHA.3040@TK2MSFTNGP14.phx.gbl...

> You'd use the ExitProcess API.  Lots of issues there
> ***snip***
>  and make sure it's the *last* thing you (intended to) do in the app.

thank you for the quick reply and link to examples.
i have examined the windows app Hello.

IMHO the *last* thing a VB app does is MDIForm_Terminate.
so i will calling ExitProcess there...unless advised to do otherwise.

thanks again,
MBB
Author
1 Jun 2005 9:58 PM
Karl E. Peterson
MB Blackburn wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:e6J$5ZuZFHA.3040@TK2MSFTNGP14.phx.gbl...
>
>> You'd use the ExitProcess API.  Lots of issues there
>> ***snip***
>>  and make sure it's the *last* thing you (intended to) do in the app.
>
> thank you for the quick reply and link to examples.
> i have examined the windows app Hello.
>
> IMHO the *last* thing a VB app does is MDIForm_Terminate.
> so i will calling ExitProcess there...unless advised to do otherwise.

Can you load/show modally the MDI from Sub Main?  I'd really lean that direction.
You could be right, in your specific case, but every app is different.  (This is
getting way non-standard at this point, of course...)
--
Working Without a .NET?
http://classicvb.org/petition
Author
2 Jun 2005 1:10 AM
Ian King
"Karl E. Peterson" <k***@mvps.org> wrote in
news:OmEr9TvZFHA.796@TK2MSFTNGP10.phx.gbl:

> Can you load/show modally the MDI from Sub Main?  I'd really lean that
> direction. You could be right, in your specific case, but every app is
> different.  (This is getting way non-standard at this point, of
> course...)

I don't think he can...

Err.Number: 403
Err.Description: MDI forms cannot be shown modally

I would vote against the practice of showing the app main form in sub main
modally because it prevents showing other forms modelessly.

Ian
Author
3 Jun 2005 1:48 AM
Karl E. Peterson
Ian King wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote in
> news:OmEr9TvZFHA.796@TK2MSFTNGP10.phx.gbl:
>
>> Can you load/show modally the MDI from Sub Main?  I'd really lean
>> that direction. You could be right, in your specific case, but every
>> app is different.  (This is getting way non-standard at this point,
>> of course...)
>
> I don't think he can...
>
> Err.Number: 403
> Err.Description: MDI forms cannot be shown modally

Yeah, that rings a bell.

> I would vote against the practice of showing the app main form in sub
> main modally because it prevents showing other forms modelessly.

I'd tend to vote against returning a result code from a windowed application, myself.
Just doesn't seem right.
--
Working Without a .NET?
http://classicvb.org/petition