Home All Groups Group Topic Archive Search About
Author
11 Apr 2005 8:07 AM
Paul Hadfield
All,

Sorry if this is a really silly question, but.....

Is it possible to set a return code for a DOS environment somewhere for a
VB.NET app?

When writing .BAT files for Windows 2000 I often need to use the ERRORLEVEL
value to determine if a program was successful or not. How can I
programmatically set this value from within VB.NET when my app exits?

Cheers,
Paul.

Author
11 Apr 2005 9:24 AM
Herfried K. Wagner [MVP]
"Paul Hadfield" <p***@anon.com> schrieb:
> Is it possible to set a return code for a DOS environment somewhere for a
> VB.NET app?

'Environment.ExitCode = <value>', 'Environment.Exit(<exit code>)', or a
'Function Main' that has a return value of type 'Integer'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
12 Apr 2005 9:31 AM
Paul Hadfield
Hi,

Neither of these seem to work. When the compiled .exe is run from a Windows
XP command prompt, neither make any difference to the %ErrorLevel% - it
remains set to 0.


Sub Main()
    Environment.ExitCode = 999
End Sub


Function Main() As Integer
    Return 999
End Function


Also, each time I run the program from within the DDE it shows:

The program '[3728] Test.exe' has exited with code 0 (0x0).

I must be missing something simple. Any ideas?


Cheers,
Paul.


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:O7xCQfnPFHA.2136@TK2MSFTNGP14.phx.gbl...
> "Paul Hadfield" <p***@anon.com> schrieb:
>> Is it possible to set a return code for a DOS environment somewhere for a
>> VB.NET app?
>
> 'Environment.ExitCode = <value>', 'Environment.Exit(<exit code>)', or a
> 'Function Main' that has a return value of type 'Integer'.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
12 Apr 2005 9:33 AM
Paul Hadfield
Sorry - I meant IDE (not DDE)

Show quoteHide quote
"Paul Hadfield" <p***@anon.com> wrote in message
news:OTpwtJ0PFHA.2356@TK2MSFTNGP14.phx.gbl...
> Hi,
>
> Neither of these seem to work. When the compiled .exe is run from a
> Windows XP command prompt, neither make any difference to the
> %ErrorLevel% - it remains set to 0.
>
>
> Sub Main()
>    Environment.ExitCode = 999
> End Sub
>
>
> Function Main() As Integer
>    Return 999
> End Function
>
>
> Also, each time I run the program from within the DDE it shows:
>
> The program '[3728] Test.exe' has exited with code 0 (0x0).
>
> I must be missing something simple. Any ideas?
>
>
> Cheers,
> Paul.
>
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:O7xCQfnPFHA.2136@TK2MSFTNGP14.phx.gbl...
>> "Paul Hadfield" <p***@anon.com> schrieb:
>>> Is it possible to set a return code for a DOS environment somewhere for
>>> a VB.NET app?
>>
>> 'Environment.ExitCode = <value>', 'Environment.Exit(<exit code>)', or a
>> 'Function Main' that has a return value of type 'Integer'.
>>
>> --
>> M S   Herfried K. Wagner
>> M V P  <URL:http://dotnet.mvps.org/>
>> V B   <URL:http://classicvb.org/petition/>
>
>
Author
12 Apr 2005 2:27 PM
Herfried K. Wagner [MVP]
Paul,

Show quoteHide quote
"Paul Hadfield" <p***@anon.com> schrieb:
> Neither of these seem to work. When the compiled .exe is run from a
> Windows XP command prompt, neither make any difference to the
> %ErrorLevel% - it remains set to 0.
>
>
> Sub Main()
>    Environment.ExitCode = 999
> End Sub
>
>
> Function Main() As Integer
>    Return 999
> End Function

Are you sure you selected 'Sub Main' as startup object in the project
properties?

> Also, each time I run the program from within the DDE it shows:
>
> The program '[3728] Test.exe' has exited with code 0 (0x0).

The IDE will report incorrect values, that's a known "bug".

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>