|
-
Feb 14th, 2001, 08:54 PM
#1
Thread Starter
Addicted Member
What must be done in order to allow my application to take in parameters, such as 'myapp.exe /myparam1 /myparam2' ?
-
Feb 14th, 2001, 09:29 PM
#2
Fanatic Member
Use the command function...
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.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 17th, 2001, 01:17 AM
#3
Addicted Member
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.
-
Feb 17th, 2001, 02:14 AM
#4
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.
-
Feb 17th, 2001, 03:05 AM
#5
Fanatic Member
If you have VB6 you can use the Split function...
Code:
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.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Feb 17th, 2001, 03:37 AM
#6
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.
Code:
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
Last edited by Lord Orwell; Feb 17th, 2001 at 03:51 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|