BBS: Inland Empire Archive Date: 11-11-93 (16:10) Number: 400 From: TOM HAMMOND Refer#: NONE To: LORD AO Recvd: NO Subj: Command Line Arguments Conf: (2) Quik_Bas
LA> Howdy. Could anybody tell me how I can grab the LA> command line parameters from a program and use 'em as LA> variables in my program? I know that ASM stores the CLP's LA> in address 080 but unfortunately that's all I know. This routine works well. I've used it for quite a while. NOTE that a couple lines were too long and have been WRAPPED to the next line. They will have to be un-wrapped (joined) before the routine will run. Wrapped lines are those which have an underline character ( _ ) at the END of the line. Good luck. Tom Hammond 'CMDPARSE.BAS 'Source: Inside QuickBASIC, May 1991, vol. 1, no. 3, pp. 9-10. DECLARE FUNCTION GetNextToken$ (aBuffer AS STRING) DECLARE SUB GetArguments (argC AS INTEGER, argV() AS STRING) CONST FALSE = 0, TRUE = NOT FALSE COMMON SHARED BreakChars$ DIM argC AS INTEGER ' command line argument count DIM argV(100) AS STRING ' command line argument array 'ANY of the following characters will be interpreted as delimiters BreakChars$ = CHR$(9) + CHR$(10) + CHR$(13) + "/ ',-:;=[]{}()" 'Note: argV(1) thru argV(argC) contain individual arguments GetArguments argC, argV() IF argC THEN FOR i = 1 TO argC PRINT i, argV(i) NEXT i PRINT END IF SUB GetArguments (argCount%, argArray$()) STATIC argCount% = 0 IF LEN(COMMAND$) > 0 THEN cmdCopy$ = COMMAND$ MoreTokens% = TRUE DO UNTIL MoreTokens% = FALSE nextTok$ = GetNextToken$(cmdCopy$) IF nextTok$ = "" THEN MoreTokens% = FALSE ELSE argCount% = argCount% + 1 argArray$(argCount%) = nextTok$ END IF LOOP END IF END SUB FUNCTION GetNextToken$ (Buffer$) STATIC ' Function to get the next token from a string of text. Token$ = "" IF LEN(Buffer$) > 0 THEN DO WHILE INSTR(BreakChars$, LEFT$(Buffer$, 1)) > 0 AND _ LEN(Buffer$) > 0 Buffer$ = RIGHT$(Buffer$, LEN(Buffer$) - 1) LOOP DO WHILE INSTR(BreakChars$, LEFT$(Buffer$, 1)) = 0 AND _ LEN(Buffer$) > 0 Token$ = Token$ + LEFT$(Buffer$, 1) Buffer$ = RIGHT$(Buffer$, LEN(Buffer$) - 1) LOOP END IF GetNextToken$ = LTRIM$(RTRIM$(Token$)) END FUNCTION $$48
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