
Getting the COMMAND line arguments in QBASIC
Quote:
> I would like to know how I get the command line arguaments in QBASIC ....?
This is very easy from a Windows DOS Prompt and quite easy from MS-DOS. The
same method can be used for QBASIC or for QuickBASIC. Firstly, here's how
to do it when running a QBASIC program from the Windows DOS Prompt.
1) Run your BASIC program
2) Use the command -- LET C$ = ENVIRON$("CMDLINE") -- to load the
command line text into C$.
C$ now contains the whole line which you typed in at the DOS prompt. You
can print it or process it in any way that you need to.
Secondly, it's not quite so satisfactory, but here's how to do it when you
are running a QBASIC program from the MS-DOS Prompt.
1) Create a little batch file called QBASIC.BAT containing these lines
SET CMDLINE=qbasic.exe
:Again
set CMDLINE=%CMDLINE% %1
SHIFT
GOTO :Again
:Done
%CMDLINE%
set CMDLINE=
2) Save that file in your DOS directory.
3) Run your BASIC program
4) Use the command -- LET C$ = ENVIRON$("CMDLINE") -- to load the
command line text into C$.
In some ways these methods are better than using the COMMAND$ function which
is built into QuickBASIC 4.5 because they give you the complete command line
whereas COMMAND$ only gives you the command line after it has been converted
to upper case and had the first "word" cut off it. Sometimes you want to
know what the case of the command line was and sometimes you want a program
to know its own name. COMMAND$ will not help you in those cases but
ENVIRON$("CMDLINE") will.
Cheers
Derek