Click to See Complete Forum and Search --> : App Parameters
Ph34R
Feb 14th, 2001, 07:54 PM
What must be done in order to allow my application to take in parameters, such as 'myapp.exe /myparam1 /myparam2' ?
YoungBuck
Feb 14th, 2001, 08:29 PM
Use the command function...
MsgBox Command
and if you want to test certain command line arguments without compiling your app goto Project/Project Properties and fill in the Command Line Arguments Edit Box.
KrishnaSantosh
Feb 17th, 2001, 12:17 AM
VB Supports Command Line Parameters
Through Command
Command Doesn't Parse The
Command Line For You. It
Just Stores The Command Line
Params As Such
In Your Example : MyAPP.Exe /myparam1 /myparam2
Command Stores "/myparam1 /myparam2".
For More Details And Samples EMail Me.
Lord Orwell
Feb 17th, 2001, 01:14 AM
its pretty easy to parse though.
dim params(10) as string
dim cl as integer
dim ltr as string
der = 0
for cl = 1 to len(command$)
do
ltr = mid$(command$, cl, 1 )
loop while ltr = " "
if ltr = / or ltr = "-" or ltr = "\" then
der = der + 1
if der = 11 then exit sub
end if
params(der) = params(der) + mid$(command$, cl, 1)
next cl
'may contain bugs. But basically, it parses command$ into an array, removing spaces.
YoungBuck
Feb 17th, 2001, 02:05 AM
If you have VB6 you can use the Split function...
Dim v
Dim iCt as Integer
v = Split(Command, " ")
For iCt = LBound(v) to UBound(v)
Debug.Print v(ict)
Next iCt
and if you have VB4 or 5 you can use the Split2 function on this thread (http://forums.vb-world.net/showthread.php?s=&postid=228949&highlight=Split2#post228949).
Lord Orwell
Feb 17th, 2001, 02:37 AM
but what results will he get if they put more than one space between parameters? That's why my little routine looped back on itself as long as it found spaces.
This is the actual sub i use in my dos vb. (with sub declaration corrections)
I did not write it. It is copied from the visual basic 1.0 help file.
SUB Comline (NumArgs as integer, Args(99) as string, MaxArgs)
CONST TRUE = -1, FALSE = 0
NumArgs = 0: in = FALSE
' Get the command line using the COMMAND$ function
Cl$ = COMMAND$
L = LEN(Cl$)
' Go through the command line a character at a time
FOR I = 1 TO L
C$ = MID$(Cl$, I, 1)
' Test for character being a blank or a tab
IF (C$ <> " " AND C$ <> CHR$(9)) THEN
' Neither blank nor tab; test if you're already inside
' an argument
IF NOT in THEN
' You've found the start of a new argument
' Test for too many arguments
IF NumArgs = MaxArgs THEN EXIT FOR
NumArgs = NumArgs + 1
in = TRUE
END IF
' Add the character to the current argument
Args$(NumArgs) = Args$(NumArgs) + C$
ELSE
' Found a blank or a tab.
' Set "Not in an argument" flag to FALSE
in = FALSE
END IF
NEXT I
END SUB
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.