In article "Multiple COMMAND$ params." (on 31.08.96), Ronald
Schlegel@1:110/1065.0 says:
Hello Ronald !!
> Does anyone know how to pass more than 1 variable to COMMAND$? I am
> trying to trap DOS environment variables...here is my example:
>
> UPLOAD %1 %2
Here's a solution:
' MYPARSE.BAS Puts each command line operand into an array. Reports number of
' operands.
' 4/17/94 - First release - by Arnie Sossner - Prodigy: VRPT68A
' For sake of demonstations, start this program with various operands.
' For example:
' Demo 1: MYPARSE
' Demo 2: MYPARSE a B c D
' Demo 3: MYPARSE /Op1 /Op2
' Demo 4 MYPARSE /?
' 4/17/94 - First release AP Sossner - Prodigy: VRPT68A
'variables
DIM Operand$(1 TO 20) 'space for twenty operands ought to
uffice
Sep$=" " 'operand separator character
'main program
CLS
IF LEN(COMMAND$)0 THEN
PRINT "The command line to be parsed: "+COMMAND$
CALL ParseCommandLine(Operand$(),OperandCount,Sep$)
ELSE
PRINT "No command line operands."
END IF
'demo of efficacy
PRINT "The number of command line operands: "+STR$(OperandCount)
FOR i = 1 to OperandCount
PRINT "Operand"+STR$(i)+": "+Operand$(i)
NEXT i
END
'subroutines
SUB ParseCommandLine(Operand$(),OperandCount,Sep$)
'Parse command line for operands. Array starts at 1, no 0; hence Operand$
'index is incremented by 1.
Cmd$ = LTRIM$(RTRIM$(UCASE$(COMMAND$))) 'your appl might not want UCASE$
OperandCount = 0
DO
Operand$(OperandCount+1) = EXTRACT$(Cmd$,Sep$) 'extract string to 1st
ep$
Cmd$ = REMOVE$(Cmd$,Operand$(OperandCount+1)) 'remove Op(i) from Cmd$
Cmd$ = LTRIM$(Cmd$) 'Change this line if Sep$ is not a space character
OperandCount = OperandCount + 1 'get next Operand$
LOOP UNTIL LEN(Cmd$) = 0
END SUB
'you might want a SELECT to decode the operands either in Main or a SUB
'SUB ProcessOperands ...
'DO
' FOR i = 1 TO OperandCount
' SELECT CASE Operand$(i)
' CASE "/?"
' ShowHelp
' SYSTEM
' CASE "A"
' DoA
' CASE "B"
' DoB
' END SELECT
' NEXT i
'END DO
'END SUB
> Thanks...
> -Ron
Regards,
----------------
/
/ h o m a s
email: author@pbsound.snafu.de
www : http://www.snafu.de/~pbsound/ (PowerBASIC's Home in Germany)
PBSOUND - The Sound Blaster Toolkit, PowerBASIC-FAQ, PowerBASIC-
sources & toolboxes, PowerBASIC on Web, PowerBASIC News and much
more or less important PowerBASIC stuff.
--- CrossPoint v3.11 R
---------------
* Origin: -= http://www.snafu.de/~pbsound/ =- (2:2410/301.12)
|