Commandline parameters via COMMAND$ function

by Moneo (no login)

Hi Pete,

Here's some thoughts about using the COMMAND$ function. For Basic programs, I'm going to tailor my discussion to compiled QuickBASIC programs since that is what I'm familiar with.

You said: " It seems to me there is nothing important to pass to a program from the command line, anyway."
Just let me say that many MSDOS utilities run from the commandline like FORMAT.COM, MODE.COM, ATTRIB.EXE, DEBUG.EXE, DOSKEY.EXE, FIND.EXE, SORT.EXE and many others, rely on commandline parameters provided by the user. The user does not need to reference a Help to get the specifications of the parameters, he can review all the parameter specs by executing the MSDOS utility followed by "a space and /?".

The famous PKZIP compacting program, forerunner of WINZIP, also runs from the MSDOS commandline with several commandline parameters. To see the parameter specs, just run PKZIP from the commandline without any parameters.

But, all of the above, you probably knew already. I just wanted to show that commandline parameters are used in a MSDOS environment.

A compiled QuickBASIC program can obtain commandline parameters by invoking the COMMAND$ function, and have the same flexibility as the above mentioned utilities. Instead of using commandline arguments, why don't you just prompt the user for the needed parameters? Simple, if, for example, the program needs 4 parameters, you need to prompt the user 4 times, which becomes very boring. As the user becomes familiar with your program, he can enter them on the commandline much quicker than being prompted. Consider why the MSDOS utilities and PKZIP use commandline parameters instead of prompts. Another advantage of commandline parameters is that the subject program, with a standard set of parameters, can be invoked from a batchfile. In this manner, the program executes with no additional user intervention.

What follows is a tiny program using COMMAND$ to convert all the characters of a given file to uppercase.
The program is called UCASE.BAS.
To convert the file called TEST.TXT to uppercase, you would run: UCASE TEST.TXT

open f$ for input as #1
open "ucase.out" for output as #2
do while not eof(1)
line input #1,d$
print #2,d$

Regards..... Moneo

Posted on Jan 5, 2009, 6:08 PM

Respond to this message   

Goto Forum Home

Response TitleAuthor and Date
not just DOSMichael Calkins on Jan 7
 *Yes, and so do winword and iexplore and most other programsArtelius on Jan 9

 Copyright © 1999-2018 Network54. All rights reserved.   Terms of Use   Privacy Statement