QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The COMMAND$ function returns the command line argument(s) passed when a program is run.


commandLine$ = COMMAND$[(count%)]



Compile both programs. ProgramA RUNs ProgramB with a parameter passed following the filename:

LOCATE 12, 36: PRINT "ProgramA"

LOCATE 23, 25: PRINT "Press any key to run ProgramB"
K$ = INPUT$(1)
RUN "ProgramB FS"  'pass FS parameter to ProgramB in QB64 or QB4.5


ProgramB checks for fullscreen parameter pass in QB64 and goes full screen.

LOCATE 17, 36: PRINT "ProgramB"
parameter$ = UCASE$(COMMAND$) 'UCASE$ is needed in QB64 only, as QB4.5 will always return upper case
LOCATE 20, 33: PRINT "Parameter = " + parameter$
IF LEFT$(parameter$, 2) = "FS" THEN _FULLSCREEN 'parameter changes to full screen



                                 Parameter = FS.EXE

Program gets the number of parameters passed to the program, and then prints those parameters to the screen one at a time.

FOR c = 1 TO count
    PRINT COMMAND$(c) 'or process commands sent

a data file

Explanation: If we start *ThisProgram.exe with the command line ThisProgram -l “a data file”, COMMAND$ will return a single string of “-1 a data file” which might be hard to process and interpret properly, but COMMAND$(1) would return “-l” and COMMAND$(2) would return the quoted “a data file” option as separate entries for easier parsing and processing.

As part of the command array syntax, you can also just read the array to see how many commands were sent (or simply check _COMMANDCOUNT):

    count = count + 1
    cmd$ = COMMAND$(count)
    IF cmd$ = "" THEN EXIT DO 'read until an empty return
    PRINT cmd$ 'or process commands sent
count = count - 1 'save the number of parameters sent to this program when run

See Also