Home All Groups Group Topic Archive Search About

Command line argument in NET

Author
2 Feb 2006 9:29 PM
hien_tran
Hello, in VB6, I could pass a parameter from VB Script to the program
and retrieve the argument using Command().  Please let me know if there
is an equivalent method in .NET.  Thank you in advance for any
assistance.

Author
2 Feb 2006 9:58 PM
Kerry Moorman
hien_tran,

The Command function is still available in VB.Net. Here is an example that
retrieves the arguments and adds them to a listbox:

        Dim myCommandString As String = Microsoft.VisualBasic.Command

        Dim myArgs() As String = myCommandString.Split(" "c)

        For Each arg As String In myArgs
            ListBox1.Items.Add(arg)
        Next

Kerry Moorman


Show quoteHide quote
"hien_t***@ghc-hmo.com" wrote:

> Hello, in VB6, I could pass a parameter from VB Script to the program
> and retrieve the argument using Command().  Please let me know if there
> is an equivalent method in .NET.  Thank you in advance for any
> assistance.
>
>
Author
2 Feb 2006 10:45 PM
alantolan
Command() still works.

You can also use the args() parameter of main which will return the
commandline 'pre-split' into arguments

e.g.

   public shared sub main(args() as string)

   end sub

hth,
Alan.
Author
2 Feb 2006 11:02 PM
Herfried K. Wagner [MVP]
<hien_t***@ghc-hmo.com> schrieb:
> Hello, in VB6, I could pass a parameter from VB Script to the program
> and retrieve the argument using Command().  Please let me know if there
> is an equivalent method in .NET.

\\\
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(...)
    End Function
End Module
///

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

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