_COMMANDCOUNT
The _COMMANDCOUNT function returns the number or arguments passed from the command line to the COMMAND$ function.
Syntax
- result& = _COMMANDCOUNT
Description
- The function returns the number of arguments passed from the command line to a program when it's executed.
- Arguments are spaced as separate numerical or text values. Spaced text inside of quotes is considered as one argument.
Availability
-
v1.1
-
all
-
yes
-
yes
-
yes
Examples
- Example
- The code below gets the number of parameters passed to our program from the command line with _COMMANDCOUNT.
'COMMAND$ index 0 is always the program name itself 'usually (but not necessarily) inclusive its full path PRINT COMMAND$(0) PRINT 'indexes 1 to _COMMANDCOUNT are the seperate arguments 'passed to the program in the same order as passed, 'quoted text counts as one argument, but quotes are usually 'already removed by the underlying console/terminal numArgs& = _COMMANDCOUNT FOR arg& = 1 TO numArgs& PRINT COMMAND$(arg&) NEXT arg& 'COMMAND$ without an index returns all given arguments 'concatenated into one string (separated by a single space) 'in the same order as passed, due to the quote removal by 'the console/terminal the string gets ambiguous, also it 'doesn't include the program name itself (index 0), hence 'it is always better to use the COMMAND$(index) syntax PRINT PRINT COMMAND$ |
Explanation If we start MyProg.exe from the command window with MyProg -l "loadfile.txt" -s "savefile.txt", the _COMMANDCOUNT would be 4 and -l, loadfile.txt, -s and savefile.txt were the arguments passed to the program, which we could then read separately with COMMAND$(n). |
See also