TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: RONALD SCHLEGEL
from: LAWRENCE GORDON
date: 1996-09-08 23:53:00
subject: Multiple COMMAND$ params.

Quoting Ronald Schlegel to Lawrence Gordon:
LG> TEST$ = COMMAND$
RS>
RS> This is amazing! Thank you very much! Just one question I neglected to
RS> ask...will this routine allow the user to enter the parameters in _any_
RS> order?
RS>
RS> Examples:
RS>
RS> PROGRAM.EXE Parm1 Parm2 Parm3
RS> PROGRAM.EXE Parm2 Parm1 Parm3
RS> PROGRAM.EXE Parm3 Parm1 Parm2
RS>
RS> Would all be valid?
As promised:
REM PARSE.BAS
TEST$ = UCASE$(COMMAND$)
CALL PARSE (TEST$, PARMSFOUND$(), 4, FOUND%, " ") 'TEST$ = string to parse 
'PARMSFOUND$() = single dimension array to hold argument variables '4 = 
number of arguments to parse (can be 0 to 9) 'FOUND% = number of arguments 
found '" " = separation character (CHR$(32)) var1$ = parmsfound$(1) var2$ = 
parmsfound$(2) var3$ = parmsfound$(3) var4$ = parmsfound$(4) 'assign each 
parameter to a variable print var1$;spc(3);var2$;spc(3);var3$;spc(3);var4$ 
'print each variable end
SUB PARSE (a$, words$(), maxwords%, wordsfound%, sep$) STATIC 'parameters 
must match call to sub parse false% = 0 true% = not false% wordsfound% = 0 
ins = false% strlen% = len(a$) for char = 1 to strlen%
 char$ = mid$(a$, char, 1)
 if char$  sep$ then
  if not ins then
   if wordsfound% = maxwords% then exit for
   incr wordsfound%
   ins = true%
   end if
 words$(wordsfound%) = words$(wordsfound%)+char$
 else
  ins = false%
 end if
next char
END SUB
REM end of PARSE.BAS
Test each variable with an IF-THEN-ELSE or CASE statement or write a routine 
to test each. 
--- InterEcho 1.19
---------------
* Origin: Toast House * (314) 994-0312 * (1:100/560)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.