Command line argument in NET

H

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

Guest

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
 
A

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

Herfried K. Wagner [MVP]

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.
 

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