Newbie VB Question

P

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.
 
H

Herfried K. Wagner [MVP]

Paul Hadfield said:
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'.
 
P

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.
 
P

Paul Hadfield

Sorry - I meant IDE (not DDE)

Paul Hadfield said:
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.
 
H

Herfried K. Wagner [MVP]

Paul,

Paul Hadfield said:
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".
 
P

Paul Hadfield

My problem appeared to be becuase I had the project output type set to
Windows Application instead of Console Applicaiton.

Cheers for your input.

Paul.

Herfried K. Wagner said:
Paul,

Paul Hadfield said:
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".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top