By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Implement Command Line Variables

P: n/a
Hello,

I was wondering if anyone knows how to parse command line variables upon
execution of an application. For example, I want to be able to type this
at a command line: "myapp.exe /cid:12353" and have "myapp.exe" open and
display a record for a client with the id of 12353.

Does anyone know how to do that. Currently I have a text box on my form
that if I enter 12353 and hit enter, the record will appear. I want this to
be possible through a command line however.

Thanks in advance.
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You can use the System.Environment.GetCommandLineArgs method to retrieve the
command line arguments in the form of an array of strings. The First
argument is the full path of your application executable
(GetCommandLineArgs(0)) - the remaining will be the arguments that you
provide on the command line. Then you can use various string functions to
retrieve the relevant values from the arguments. For instance, for the
argument that you've mentioned, you could do something like this (watch for
typos - typed directly here):

Dim arg1 As String = _
System.Environment.GetCommandLineArgs(1)

Dim ID As Integer = Integer.Parse( _
arg1.SubString(arg0.IndexOf("/cid:") + 1))

This will give you the customer ID 12353.

hope that helps..
Imran.

"Stewart Saathoff" <sd********@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
Hello,

I was wondering if anyone knows how to parse command line variables upon
execution of an application. For example, I want to be able to type this
at a command line: "myapp.exe /cid:12353" and have "myapp.exe" open and
display a record for a client with the id of 12353.

Does anyone know how to do that. Currently I have a text box on my form
that if I enter 12353 and hit enter, the record will appear. I want this
to be possible through a command line however.

Thanks in advance.

Nov 21 '05 #2

P: n/a
"Stewart Saathoff" <sd********@hotmail.com> schrieb:
execution of an application. For example, I want to be able
to type this at a command line: "myapp.exe /cid:12353" and have
"myapp.exe" open and display a record for a client with the id
of 12353.


\\\
Public Module Program
Public Sub Main(ByVal Args() As String)
If Args.Length > 0 Then

' 'Args' is a string array that contains the command line
' parameters' values.
End If
End Sub
End Module
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #3

P: n/a
Could you explain what you have put here?

Stewart
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oe**************@TK2MSFTNGP15.phx.gbl...
"Stewart Saathoff" <sd********@hotmail.com> schrieb:
execution of an application. For example, I want to be able
to type this at a command line: "myapp.exe /cid:12353" and have
"myapp.exe" open and display a record for a client with the id
of 12353.


\\\
Public Module Program
Public Sub Main(ByVal Args() As String)
If Args.Length > 0 Then

' 'Args' is a string array that contains the command line
' parameters' values.
End If
End Sub
End Module
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4

P: n/a
I get a message that states "Input string in invalid format." Do you know
what causes that?
"Imran Koradia" <no****@microsoft.com> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
You can use the System.Environment.GetCommandLineArgs method to retrieve
the command line arguments in the form of an array of strings. The First
argument is the full path of your application executable
(GetCommandLineArgs(0)) - the remaining will be the arguments that you
provide on the command line. Then you can use various string functions to
retrieve the relevant values from the arguments. For instance, for the
argument that you've mentioned, you could do something like this (watch
for typos - typed directly here):

Dim arg1 As String = _
System.Environment.GetCommandLineArgs(1)

Dim ID As Integer = Integer.Parse( _
arg1.SubString(arg0.IndexOf("/cid:") + 1))

This will give you the customer ID 12353.

hope that helps..
Imran.

"Stewart Saathoff" <sd********@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
Hello,

I was wondering if anyone knows how to parse command line variables upon
execution of an application. For example, I want to be able to type
this at a command line: "myapp.exe /cid:12353" and have "myapp.exe" open
and display a record for a client with the id of 12353.

Does anyone know how to do that. Currently I have a text box on my form
that if I enter 12353 and hit enter, the record will appear. I want this
to be possible through a command line however.

Thanks in advance.


Nov 21 '05 #5

P: n/a
probably this:
arg1.SubString(arg0.IndexOf("/cid:") + 1))

Should be:
arg1.SubString(arg1.IndexOf("/cid:") + 1))

Rinze

Stewart Saathoff wrote:
I get a message that states "Input string in invalid format." Do you know
what causes that?
"Imran Koradia" <no****@microsoft.com> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
You can use the System.Environment.GetCommandLineArgs method to retrieve
the command line arguments in the form of an array of strings. The First
argument is the full path of your application executable
(GetCommandLineArgs(0)) - the remaining will be the arguments that you
provide on the command line. Then you can use various string functions to
retrieve the relevant values from the arguments. For instance, for the
argument that you've mentioned, you could do something like this (watch
for typos - typed directly here):

Dim arg1 As String = _
System.Environment.GetCommandLineArgs(1)

Dim ID As Integer = Integer.Parse( _
arg1.SubString(arg0.IndexOf("/cid:") + 1))

This will give you the customer ID 12353.

hope that helps..
Imran.

"Stewart Saathoff" <sd********@hotmail.com> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
Hello,

I was wondering if anyone knows how to parse command line variables upon
execution of an application. For example, I want to be able to type
this at a command line: "myapp.exe /cid:12353" and have "myapp.exe" open
and display a record for a client with the id of 12353.

Does anyone know how to do that. Currently I have a text box on my form
that if I enter 12353 and hit enter, the record will appear. I want this
to be possible through a command line however.

Thanks in advance.



Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.