is it possible to send any arguments to a standard exe prepared using vb? if yes, how to use these arguments in the startup modules or forms of the exe?
Printable View
is it possible to send any arguments to a standard exe prepared using vb? if yes, how to use these arguments in the startup modules or forms of the exe?
Yes it is possible.
Use the Command() function to get the argument of your program
Code:dim CmdLine as string
CmdLine = Command()
' Treatment of the CmdLine
...
Let said you wish your VB program to accept an command line "/%1 /config"
then all you need is put this under the Sub Main() or Form_Load() procedure.
Code:Option Explicit
Private MyCmdLine As String
Public Sub Main()
MyCmdLine = Command()
If MyCmdLine = "/%1 /config" then
'Do whatever you've plan.
Else
'Do whatever you don't want your program do.
End If
End Sub
Or....
Private Sub Form_Load()
MyCmdLine = Command()
If MyCmdLine = "/%1 /config" then
'Do whatever you've plan.
Else
'Do whatever you don't want your program do.
End If
End Sub
Like operator is fast and easy if you want to put flags in your command line:
Code:Public Sub Main()
MyCmdLine = Command()
If MyCmdLine like "*/a*" then 'Do what you what
If MyCmdLine like "*/b*" then 'Do what you what
If MyCmdLine like "*/c*" then 'Do what you what
If MyCmdLine like "*/d*" then 'Do what you what
If MyCmdLine like "*/e*" then 'Do what you what
End Sub