Re: COMMAND LINE PARM's

 BBS: Inland Empire Archive
Date: 03-05-92 (18:39)             Number: 183
From: RICK PEDLEY                  Refer#: NONE
  To: ZACK JONES                    Recvd: NO  
Subj: Re: COMMAND LINE PARM's        Conf: (11) Modula-2

On 03-02-92 ZACK JONES wrote to Zack Jones... ZJ> these two file names as command line paramaters? What I'd ZJ> like to be able to do is type "Qcopy Sourcefile ZJ> Outputfile" instead of using the INPUT statements. 'Command line parser. DEFINT A-Z C$ = COMMAND$ + " " 'so we have parm-space-parm-space-parm-space... MaxParms = 2 MinParms = 2 DIM Parm$(MaxParms) ParmCnt = 0 FOR x = 1 TO LEN(C$) 'replace any tabs with spaces. IF MID$(C$, x, 1) = CHR$(9) THEN MID$(C$, x, 1) = " " NEXT x DO sp = INSTR(C$, " ") IF sp THEN ParmCnt = ParmCnt + 1 Parm$(ParmCnt) = LEFT$(C$, sp - 1) C$ = LTRIM$(MID$(C$, sp + 1)) 'LTRIM strips multiple leading spaces. END IF LOOP UNTIL ParmCnt = MaxParms OR C$ = "" IF ParmCnt < MinParms THEN PRINT "At least"; MinParms; "parameters required." END 'or whatever, maybe leave ELSE 'the INPUT code in place FOR x = 1 TO ParmCnt 'to handle this condition. PRINT Parm$(x) NEXT x END IF This is more general purpose than you need, but will work for any number of parameters by changing MaxParms and MinParms. PKZIP for example, must deal with numerous optional parameters, but in this case we need exactly two, so MinParms & MaxParms are equal. ... OFFLINE 1.36 * I just found the last bug. --- Maximus 2.01wb * Origin: The BULLpen BBS * Intel 14.4EX (613)549-5168 (1:249/140)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET