473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can a console VB.NET prog return a value to caller?

Greetings,
Since Main() is a subroutine in VB.NET console apps and not a function, is
there a way to return a value to a script ro other "caller" for a VB.NET
console .exe?
sub main()
like
if file.exists(myF ile)
return 1 'file downloaded
else
return 0 'file not downloaded
exit sub
Any ideas? Am I missing something simple...?

thanks,
johnny
Mar 8 '06 #1
6 15476
> Since Main() is a subroutine in VB.NET console apps and not a function, is

Main may be also function:
Function Main(ByVal CmdArgs() As String) As Integer

See
http://msdn.microsoft.com/library/de...helloworld.asp

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Mar 8 '06 #2
"johnnyG" <jo*****@discus sions.microsoft .com> schrieb:
Since Main() is a subroutine in VB.NET console apps and not a function, is
there a way to return a value to a script ro other "caller" for a VB.NET
console .exe?


\\\
Public Module Program
Public Function Main(ByVal Args() As String) As Integer
For Each Arg As String In Args
MsgBox(Arg)
Next Arg
Application.Run (New MainForm())
If...Then
Return 0
Else
Return 1
...
End If
End Function
End Module
///

Select 'Sub Main' as startup object in the project properties.

Alternatively you can use 'Application.Ex it(<exit code>)' or set
'Environment.Ex itCode' to the exit code.

Note that the IDE won't show the correct exit code when debugging.

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

Mar 8 '06 #3
Herfried,

I have been asked to amend a number of .Net 1.1 batch processes so that they
return an exit code of 0 when it was successful and an exit code of 1 when it
fails. I have been playing with Environment.Exi tCode and Environment.Exi t.
As you mention here VS.Net 2003 always displays an exit code of 0 in the
Debug Window. How else can I tell what the exit code is after running the
..exe? I can't figure out how to test that Environment.Exi t(1) actually
returns 1 and not the default 0.

Any help would be greatly appreciated

Regards

John
"Herfried K. Wagner [MVP]" wrote:
"johnnyG" <jo*****@discus sions.microsoft .com> schrieb:
Since Main() is a subroutine in VB.NET console apps and not a function, is
there a way to return a value to a script ro other "caller" for a VB.NET
console .exe?


\\\
Public Module Program
Public Function Main(ByVal Args() As String) As Integer
For Each Arg As String In Args
MsgBox(Arg)
Next Arg
Application.Run (New MainForm())
If...Then
Return 0
Else
Return 1
...
End If
End Function
End Module
///

Select 'Sub Main' as startup object in the project properties.

Alternatively you can use 'Application.Ex it(<exit code>)' or set
'Environment.Ex itCode' to the exit code.

Note that the IDE won't show the correct exit code when debugging.

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

May 4 '06 #4
John Read wrote:
How else can I tell what the exit code is after running the .exe?
I can't figure out how to test that Environment.Exi t(1) actually
returns 1 and not the default 0.


You could put up a dialog with the intended result just before leaving
the program (when the Debugger's attached, of course), but you'd still
be relying on the Exit code being returned correctly.
The only way to confirm /that/ is to run the program "for real" and test
the value returned.

[test.bat]
start /wait program.exe rubbish arguments
echo %ERRORLEVEL%

HTH,
Phill W.
May 4 '06 #5
That did the trick, my knowledge of MSDOS is quite limited :)

Thanks

John

"Phill W." wrote:
John Read wrote:
How else can I tell what the exit code is after running the .exe?
I can't figure out how to test that Environment.Exi t(1) actually
returns 1 and not the default 0.


You could put up a dialog with the intended result just before leaving
the program (when the Debugger's attached, of course), but you'd still
be relying on the Exit code being returned correctly.
The only way to confirm /that/ is to run the program "for real" and test
the value returned.

[test.bat]
start /wait program.exe rubbish arguments
echo %ERRORLEVEL%

HTH,
Phill W.

May 4 '06 #6
Watch out for the %ErrorLevel% variable. You need to test for higher
numbered error codes first as it %errorlevel% returns true if the return
code is equal to or greater than the tested level. Also, %errorlevel% is
only documented to support errorlevels 0 to 255.

Mike Ober.

"John Read" <Jo******@onlin e.nospam> wrote in message
news:4A******** *************** ***********@mic rosoft.com...
That did the trick, my knowledge of MSDOS is quite limited :)

Thanks

John

"Phill W." wrote:
John Read wrote:
How else can I tell what the exit code is after running the .exe?
I can't figure out how to test that Environment.Exi t(1) actually
returns 1 and not the default 0.


You could put up a dialog with the intended result just before leaving
the program (when the Debugger's attached, of course), but you'd still
be relying on the Exit code being returned correctly.
The only way to confirm /that/ is to run the program "for real" and test
the value returned.

[test.bat]
start /wait program.exe rubbish arguments
echo %ERRORLEVEL%

HTH,
Phill W.


May 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1948
by: Michael Klatt | last post by:
class Foo { public : explicit Foo(int i) : m_int(i) {} private : int m_int; }; Foo f(int i)
8
13992
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on stack. this contains the arguments this function was called with, address to return to after return from this function (the location in the previous...
3
2343
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They do work pretty well, except for the change I made to get the return value. For example, I have the following:...
20
3578
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this exit(n)) statement provide both function call and return features of the C programming language? /* headers omitted */ int main (void)
6
1884
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document that describes this. Here's the setup. We have a COM server, written in Python. For completeness, here is the script: ----- testserver.py...
16
2594
by: DaTurk | last post by:
Hi, I have a c# application that needs to access c++ libraries, so it does this by using a managed layer of c++ CLI. Anyway, in the CLI function call, that calls the unmanaged function it expects a boolean return value, which it gets, but the value changes! I walked throuhg the code, and the unmanged code is returning false, but when I look...
2
1790
by: Mick Walker | last post by:
Public Sub CheckProduct(ByVal _ConnString As String, ByVal ProductList As List(Of Import_ImportLines.Lines)) Dim ReturnValue As Integer = 0 ' Our Return Value Dim conn As New SqlConnection Dim cmd As New SqlCommand conn.ConnectionString = _ConnString cmd.Connection = conn cmd.CommandType = Data.CommandType.StoredProcedure cmd.CommandText =...
7
10306
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer) As Boolean Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean If...
12
5124
by: Dooza | last post by:
I have a stored procedure that takes a number of inputs, does a bulk insert, and then outputs a recordset. When I run the stored procedure in Server Management Studio I also get a return value from the stored procedure which is an INT. I want to access this return value on my ASP/VBScript page, but do not know how to access it. Here is...
1
5759
by: Derek Hart | last post by:
I am using an MSScriptControl in vb.net to do an evaluation of a text string: tempAnswer = MyScriptControl.Eval(MyScriptString) But how can I use this to get a return value from a vbscript function: Function Foo() As Integer If MyValue = 1 Then Foo=1 Else
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.