Home All Groups Group Topic Archive Search About

How to recognize a Command Line parameter?

Author
29 Nov 2006 6:48 AM
Anil Gupte
I am trying to send a command line parameter to a utilty I wrote. For
example:

c:\utilities\powerbuddy.exe 50

The 50 can be any number.

How do I see it in the program?  Do I have to create a Main rountine and
pass it the value?  If so how?  And then, how do I load the main form of the
applicaiton from the Main sub?

Thanx,

Author
29 Nov 2006 8:09 AM
Herfried K. Wagner [MVP]
"Anil Gupte" <anil-l***@icinema.com> schrieb:
>I am trying to send a command line parameter to a utilty I wrote. For
>example:
>
> c:\utilities\powerbuddy.exe 50
>
> The 50 can be any number.
>
> How do I see it in the program?  Do I have to create a Main rountine and
> pass it the value?  If so how?  And then, how do I load the main form of
> the applicaiton from the Main sub?

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/95ee4737bce72df5>

Loading the form:

\\\
Application.Run(New MainForm())
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
29 Nov 2006 10:00 AM
Anil Gupte
I am getting No accessible 'Main' method with an appropriate signature was
found in 'PowerBuddy'.

Where do I put this:
Public Module Program

Public Sub Main(ByVal Arg As Integer)

End Sub

End Module

I right clicked on the solution and picked "Add Module".  Then I added the
Sub Main and made the module Public.  Still I am getting the abvoe error.

Thanx,
Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:uS2Rk24EHHA.3616@TK2MSFTNGP02.phx.gbl...
> "Anil Gupte" <anil-l***@icinema.com> schrieb:
>>I am trying to send a command line parameter to a utilty I wrote. For
>>example:
>>
>> c:\utilities\powerbuddy.exe 50
>>
>> The 50 can be any number.
>>
>> How do I see it in the program?  Do I have to create a Main rountine and
>> pass it the value?  If so how?  And then, how do I load the main form of
>> the applicaiton from the Main sub?
>
> <URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/95ee4737bce72df5>
>
> Loading the form:
>
> \\\
> Application.Run(New MainForm())
> ///
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
29 Nov 2006 1:45 PM
Herfried K. Wagner [MVP]
"Anil Gupte" <anil-l***@icinema.com> schrieb:
>I am getting No accessible 'Main' method with an appropriate signature was
>found in 'PowerBuddy'.
>
> Where do I put this:
> Public Module Program
>
> Public Sub Main(ByVal Arg As Integer)

The 'Main' sub expects an array of strings as shown in my sample.  You'll
have to perform your own conversion:

\\\
Public Sub Main(ByVal Args() As String)
    Dim Number As Integer
    If Args.Length > 0 Then
        Number = CInt(Args(0))
    Else
        ...
    End If
End Sub
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
29 Nov 2006 12:26 PM
Kerry Moorman
Anil,

An easy way is to use VB's Command function.

No need to go the Sub Main, etc route just to get the command line args. If
your program currently starts with a startup form, just use the Command
functionfrom code on the form.

Kerry Moorman


Show quoteHide quote
"Anil Gupte" wrote:

> I am trying to send a command line parameter to a utilty I wrote. For
> example:
>
> c:\utilities\powerbuddy.exe 50
>
> The 50 can be any number.
>
> How do I see it in the program?  Do I have to create a Main rountine and
> pass it the value?  If so how?  And then, how do I load the main form of the
> applicaiton from the Main sub?
>
> Thanx,
> --
> Anil Gupte
> www.keeninc.net
> www.icinema.com
>
>
>
Author
29 Nov 2006 2:28 PM
Michel Posseth [MCP]
you can do this in several ways


In VB < .Net  there was  Command$ and it is in VB.Net
Command()
Orelse   (only  VB.Net 2005 :-)  )    
My.Application.CommandLineArgs

regards

Michel Posseth 






Show quoteHide quote
"Anil Gupte" wrote:

> I am trying to send a command line parameter to a utilty I wrote. For
> example:
>
> c:\utilities\powerbuddy.exe 50
>
> The 50 can be any number.
>
> How do I see it in the program?  Do I have to create a Main rountine and
> pass it the value?  If so how?  And then, how do I load the main form of the
> applicaiton from the Main sub?
>
> Thanx,
> --
> Anil Gupte
> www.keeninc.net
> www.icinema.com
>
>
>