CommandLineArgs Property


CommandLineArgs Property

Location

My.Application.CommandLineArgs

Syntax

     Dim result As System.Collections.ObjectModel.ReadOnlyCollection( _        Of String) = My.Application.CommandLineArgs 

Description

The CommandLineArgs property returns a collection of each space-delimited argument from the command-line text used to initiate the application. This collection includes the arguments only; the application path used to start the application is not included. The System.Environment.CommandLine property, on the other hand, includes the application path.

Usage at a Glance

  • This property is read-only.

  • If your application is configured to run as a single instance only, this property will always return the command-line arguments for the initial instance. To view the arguments for subsequent instances, use the My.Application.StartupNextInstance event and examine the CommandLine property of the second parameter (e) for that event.

Example

The following example looks for the argument "/?" and takes action when found.

         Private Sub CheckCommandOptions(  )            Dim scanArg As String            For Each scanArg In My.Application.CommandLineArgs               If (scanArg = "/?") Then                  ' ----- Show application usage.                  MsgBox("syntax: PrintInColor.exe [filename]")                  End               End If            Next scanArg     End Sub 

Related Framework Entries

  • Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase.CommandLineArgs Property

  • Microsoft.VisualBasic.ApplicationServices.StartupEventArgs.CommandLine Property

  • System.Environment.CommandLine Property

See Also

Application Object, GetEnvironmentVariable Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net