Click to See Complete Forum and Search --> : Adding parameters to my application
web_mickey
August 8th, 2001, 02:32 PM
How can I use parameters whith my application???
like:
C:\MYAPP.EXE /s /r /t /y /start /t:34
etc.
Add handle them in my program
thanks
web_mickey
deghost
August 8th, 2001, 02:40 PM
check out the Command$ function, it returns the parameters and then you can do split(s,"/") or something to separate them
----------
The @host is everywhere!
----------
michi
August 8th, 2001, 03:18 PM
You can use Command() to get the commandline string, and then split the parameters. Like this:
=============
Option Explicit
Public Sub Main()
Dim rv As String 'return value
Dim i As Integer
i = InStr(1, Command(), "/s", vbTextCompare)
'Check if key exists
If i > 0 Then
'Do something to handle "/s"
MsgBox "Found /s!"
End If
i = InStr(1, Command(), "/r", vbTextCompare)
'Check if key exists
If i > 0 Then
'Do something to handle "/r"
MsgBox "Found /r!"
End If
''''''''''''
'TO DO: Add any cases if you want
'''''''''''
i = InStr(1, Command(), "/t:", vbTextCompare)
'Check if key exists
If i > 0 Then
'strip off the key name plus all key-value pairs that came before the target key
'ie. get value of key + anything after it
rv = Mid(Command(), i + Len("/t:"))
'strip off next key
i = InStr(rv, "/")
If i > 0 Then
rv = Left(rv, i)
End If
'Return the value
rv = Trim(rv)
If rv <> "" Then
'TO DO: handle with the value ( for example: rv="34")
MsgBox "Found /t! vale=" & rv
Else
rv = "Exists"
End If 'Do something to handle "/r"
End If
End Sub
============
HTH
Regards,
Michi
John G Duffy
August 8th, 2001, 03:36 PM
The previous two appends describe the Command$ statement to retrieve command line parameters.
In order to simulate command line parameters at DESIGN time, go to Project/Project Properties. Select the MAKE tab and enter your parameters in the "Command Line Arguments:" box.
When your program issues the Command$ statement, whatever you specify here will be presented.
John G
web_mickey
August 9th, 2001, 07:40 AM
Thank you for your help !!!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.