Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameter to Application 1

Status
Not open for further replies.

mOOdY4u

Programmer
Aug 11, 2008
5
Hey all,

how can i pass parameter to my project at the run time,

the code is
------------------------------------
Dim p As New System.Diagnostics.ProcessStartInfo()
p.Verb = "print"
p.WindowStyle = ProcessWindowStyle.Hidden
p.FileName = "c:\somefile.pdf"
p.UseShellExecute = True
System.Diagnostics.Process.Start(p)
------------------------------------

so i want to send the value of (p.FileName) at the run time
like this

cmd > myApplication.exe "c:\somethingElse.pdf"

i wish it's clear 4 u


thx in advance


 
I think there is a way to do this, i haven't seen it though.

I remember seeing something about initial arguments for the application with C++.


What you can do is create a config file for the app, and as long as that file doesn't change often, you can place the value(s) in the config file.

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Take a look at System.Environment.GetCommandLineArgs()

This returns an array of string for each command line argument you pass.

If I'm not mistaken the first element in the array is for the name of the executable running. The second element will be the command line.

Code:
For Each CommandLineArgument As String In System.Environment.GetCommandLineArgs()
    MessageBox.Show(CommandLineArgument)
Next


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Yes, use ...GetCommandLineArgs() it will create a string array of the arguments. GetCommandLineArgs.Length will give you the number of arguments that were specified in the command line. As George posted, you can then evaluate these and do what ever you want. I use them for periodically running some procedures within my program by scheduling them in the windows scheduler and including the proper arguments. This allows the user to run the procedures on demand within the program and/or on a scheduled basis. If my program does not see any arguments, it continues with it's normal startup allowing me to use the same program for scheduled tasks and normal startups. I just had to make sure there were was no user interaction required when called by the scheduled version.

Auguy
Northwest Ohio
 
What I usually do is create a module with a public variable of the parameter you are passing in and like the others have mentioned use GetCommandLineArgs. With the below you can add multiple paramters.

Code:
    Public parameter As String 'this will be the parameter you pass in

    Public Sub CommandLineArgs()
        Try
            Dim s = Environment.GetCommandLineArgs()
            Dim x As String
            For Each x In s
                Select Case Left(x, 5)
                   Case "var1:"
                        parameter = CStr(Strings.Right(x, Len(x) - 5))
                End Select
            Next
        Catch x As Exception
            MsgBox(x.Message)
        End Try
    End Sub
[code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top