Command line argument in NET

  • Thread starter Thread starter hien_tran
  • Start date Start date
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.
 
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
 
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.
 
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.
 
Back
Top