home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Boston 2
/
boston-2.iso
/
DOS
/
PROGRAM
/
BASIC
/
POWBASIC
/
LIBRARY6
/
PRSCMD.ZIP
/
PARSECMD.BAS
Wrap
BASIC Source File
|
1990-09-09
|
2KB
|
66 lines
$IF 0
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
This code is based on an example from Henry Piper's (72330,1721)
posting in the Spectra area of the PCVenB forum on Compurserve of
September 6, 1990
Made into a sub 9/9/90 by Barry Erick 75300,214
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The code between the 'Here and 'ToHere should be included to use this.
Two variables result. NumArgs% returns the number of parameters on
the command line. The string array Args$() returns the actual arguments.
Testing this demo can be done this way: compile and run from
the command line as
ParseDemo First Second /another /stillanother andmore last
The demo code will print the number of parameters and the actual
parameters.
This can also be run from within the IDE my using Alt/O/P and entering
the parameters before running with F9
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$ENDIF
DEFINT a-z
'Here
%False = 0
%True = -1
SUB ParseCmds
SHARED Args$(),NumArgs%
LOCAL Included%,StrLen%
NumArgs% = 0
Included% = %False
REDIM Args$(25)
Cmd$ = COMMAND$
StrLen% = LEN(cmd$)
FOR I = 1 TO StrLen
Temp$ = MID$(Cmd$,i,1)
IF (Temp$ <> " " AND Temp$ <> CHR$(9) AND_
Temp$ <> "/" AND Temp$<>"-") THEN
IF NOT Included% THEN
NumArgs% = NumArgs% + 1
Included% = %True
END IF
Args$(NumArgs%) = Args$(NumArgs%) + Temp$
ELSE
Included% = %False
END IF
NEXT
END SUB
'ToHere
' Main Demo
CALL ParseCmds
PRINT "There are";numargs; "commands on the command line"
FOR i = 1 TO numargs
PRINT "Argument number";i;" is: ";args$(i)
NEXT
END