|
|
Title | Read command line parameters in VB 2005 |
Description | This example shows how to read command line parameters in VB 2005. |
Keywords | command line, commandline, command line parameters, parameters, VB 2005 |
Categories | Software Engineering, Windows, Tips and Tricks |
|
|
The My.Application.CommandLineArgs collection contains the program's command-line arguments and values in the format:
parameter=value
The following code loops through the parameters. It uses IndexOf to find the position of the "=" character, separates the parameter's name and value, and adds them to the form's DataGridView control.
|
|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
For Each param As String In _
My.Application.CommandLineArgs
' Separate the parameter name and value.
Dim param_name As String
Dim param_value As String
Dim pos As Integer = param.IndexOf("=")
If pos < 0 Then
param_name = param
param_value = ""
Else
param_name = param.Substring(0, pos)
param_value = param.Substring(pos + 1)
End If
DataGridView1.Rows.Add(New Object() {param_name, _
param_value})
Next param
End Sub
|
|
To specify command line parameters for use in the design environment, double-click My Project, select the Debug tab, and enter values in the "Command line arguments" box.
Visual Basic separates parameters at spaces. To include a space character in a parameter name or value, enclose it in double quotes. Visual Basic removes the quotes from the value in the CommandLineArgs collection.
To specify
|
|
|
|
|
|