# Passing pamaters in VB generated exe



## rohitpabby (Aug 14, 2001)

Hi All!

How can we pass parameters in an exe of VB project? What all we have to do in the Standard Exe project for this. Please help....

Thanks.


----------



## TimCottee (Oct 10, 2001)

I assume that you mean how do you pass a set of parameters on the command line of the application that can be interpreted and actioned. If so then here is the method:

Private Sub Form_Load()
Dim strCommand As String
Dim aryParameters() As String
Dim intParam As Integer
'Get command line
strCommand = Command()
'Parse parameters assuming seperated by spaces
aryParameters = Split(strCommand," ") 
'Display the passed parameters, here is where you would determine what to do with them instead
strCommand = ""
For intParam = LBound(aryParameters) To UBound(aryParameters)
strCommand = "Parameter " & CStr(intParam) & " = " & aryParameters(intParam) & vbLF
Next
Msgbox strCommand
End Sub


----------



## DJ [email protected] (Aug 8, 2001)

hey.. can anyone explain the msg above in english for me??? wat sring is the actual command parameter??? and how do you make the parameter change the program???


----------



## TimCottee (Oct 10, 2001)

The actual command line parameters are returned in the Command$ or Command() function. So if you call an application from a command line like this:

MyApplication Parameter1 Parameter2

Then the value of Command() will be "Parameter1 Parameter2"

The split command just chops this up into array elements

ary(0) = "Parameter1"
ary(1) = "Parameter2"

You can then execute code which does something different depending on these values.


----------



## marcela (Sep 8, 2004)

i have a application that i call from asp and i need to pass a parameter for it..

in asp a call
objShell.Run("C:/Temp/exe2vb/Project1.exe "& tipoAtivo)

and in my application
i use
strCommand = Command()
aryParameters = Split(strCommand, " ")
tipoAtivo = aryParameters 

the problem : i don´t get receive my parameter in my exe...

i seach in all places...and look the same i do and don´t work

i need this as soon as possible


----------



## TimCottee (Oct 10, 2001)

If you add a msgbox in the startup of your program such as:


```
Msgbox Command()
```
Do you see any value having been passed through? If so then it is not a problem with getting the parameter in, more a case of not picking up the correct element in the array. Looking at your example, there is more than a single space character between the end of the executable name and the parameter string you are passing. This would mean that you need tipoAtivo = aryParameters(1) which is the second element in the array as the array is zero based.


----------



## marcela (Sep 8, 2004)

hi tim,

i continue have the problem...

i put 
mess = objShell.Run("C:/Temp/exe2vb/Project1.exe "&tipoAtivo)

If(mess=0) Then
Response.Write("ok")
Else
Response.Write("not ok")
End If 

here objshell.run return mess = 0 like a get run my application..

and in my application 

Dim aryParameters() As String
Dim strCommand As String
Dim tipoAtivo As String

strCommand = Command()
aryParameters = Split(strCommand, " ")
tipoAtivo = aryParameters(1)

and continue without parameter..
i don´t know what is wrong??
i can´t read de parameter from msgbox..


----------



## Nok1 (Feb 16, 2004)

since you're making a local array, try using the ubound() and lbound() of Command() and seeing what the the upper and lower bounds are. You could also make a for loop to go from lower bound to upper bound and see whats going on there. Hope that helped.


----------



## dimention (Oct 31, 2004)

rohitpabby said:


> Hi All!
> 
> How can we pass parameters in an exe of VB project? What all we have to do in the Standard Exe project for this. Please help....
> 
> Thanks.


----------

