Command-Line Parameters

 BBS: Inland Empire Archive
Date: 03-04-92 (03:04)             Number: 143
From: SCOTT WUNSCH                 Refer#: NONE
  To: ZACK JONES                    Recvd: NO  
Subj: Command-Line Parameters        Conf: (11) Modula-2

On 2 March 1992 Zack Jones wrote to All... ZJ> Greetings All, ZJ> I'm learing QuickBASIC - mainly from typing in programs written in ZJ> magazines (but hey, I've gotta start somewhere). Anyway - one ZJ> program I typed in recently is called Qcopy and is from the ZJ> Jan 90 issue of PC Hands On. Basically what the program ZJ> does is while copying a file it displays a bargraph showing ZJ> % completed. The program prompts you for the Source File ZJ> and Output file using INPUT statements. How can I modify ZJ> the program to pass these two file names as command line ZJ> paramaters? What I'd like to be able to do is type "Qcopy ZJ> Sourcefile Outputfile" instead of using the INPUT ZJ> statements. Thanks in advace for the help. Take Care, ZJ> Zack Jones. Use COMMAND$. For example: CommandLine$ = COMMAND$ SpacePos% = INSTR(CommandLine$, " ") IF SpacePos% THEN SourceFile$ = LEFT$(CommandLine$, SpacePos% - 1) OutputFile$ = MID$(CommandLine$, SpacePos% + 1) ELSE PRINT "Usage: QCOPY sourcefile outputfile END END IF . . . The first thing the program does is define variables to the values of the two functions it will be using. This is done for speed - so that you don't have to call the functions more than once. Next, it makes sure there is a space, indicating two filenames (note that this could be improved to check for extra parameters). Then, it just uses LEFT$ and MID$ to trim off the appropriate amount for the two file names. The two filenames have now been defined, and all that's left is handling invalid parameters. Not that hard, is it? -= Scott =- ... OFFLINE 1.36 * PRINT "I "; CHR$(3); " BASIC!" --- Maximus 2.00 * Origin: The Green Zone - Regina, Sask, Canada (1:140/23)
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