Implement Command Line Variables

  • Thread starter Thread starter Stewart Saathoff
  • Start date Start date
S

Stewart Saathoff

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.
 
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 said:
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
///
 
I get a message that states "Input string in invalid format." Do you know
what causes that?
 
probably this:
arg1.SubString(arg0.IndexOf("/cid:") + 1))

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

Rinze
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top