Creating Optional Commandline Parameters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I create optional parameters that can be included in the command line of a windows forms application

Michael
 
* "=?Utf-8?B?bWljaGFlbA==?= said:
How can I create optional parameters that can be included in the command line of a windows forms application?

Open the project's properties dialog, choose "Configuration settings" ->
"Debugging" -> "Start options" -> "Command line arguments".
 
michael said:
Okay, I can see how to add parameters from within the Project's Property
dialog(I assume you can add the same parameters after projectname.exe
from a run command prompt). But, how can you recover the value of theses
parameters from within your code at run time. I just can't seem to find
this in the help files.


You'll need to do this in your application entry point. I like to start my
applications like so:


Public Class ApplicationEntryPoint

<STAThread()> _
Public Shared Sub Main(ByVal cmdArgs() As String)
'The cmdArgs parameter contains the command line arguments.
Application.Run('Whatever)
End Sub

End Class
 
* "=?Utf-8?B?bWljaGFlbA==?= said:
Okay, I can see how to add parameters from within the Project's
Property dialog(I assume you can add the same parameters after
projectname.exe from a run command prompt). But, how can you recover the
value of theses parameters from within your code at run time. I just
can't seem to find this in the help files.

This code shows you how to get the passed data:

\\\
Public Sub Main(ByVal astrCmdLineArgs() As String)
Dim i As Integer
For i = 0 To astrCmdLineArgs.Length - 1
Console.WriteLine(astrCmdLineArgs(i))
Next i
End Sub
///

- or -

\\\
Public Sub Main()
Dim i As Integer
For i = 0 To Environment.GetCommandLineArgs().Length - 1
Console.WriteLine(Environment.GetCommandLineArgs(i))
Next i
End Sub
///

Notice that the startup object must be set to 'Sub Main'.
 
Back
Top