COMMANDCOUNT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:


{{PageDescription}}
{{PageDescription}}
* The function returns the number of arguments passed from the command line to a program when it's executed.
* 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.  
* Arguments are spaced as separate numerical or text values. Spaced text inside of quotes is considered as one argument.
* In C, this function would generally be regarded as 'argc' when the main program is defined as the following: '''int main(int argc, char *argv[])'''
* In C, this function would generally be regarded as 'argc' when the main program is defined as the following: '''int main(int argc, char *argv[])'''




{{PageExamples}}
{{PageExamples}}
''Example:'' The code below gets the number of parameters passed to our program from the command line with _COMMANDCOUNT:  
''Example:'' The code below gets the number of parameters passed to our program from the command line with _COMMANDCOUNT:
{{CodeStart}}limit = {{Cl|_COMMANDCOUNT}}
{{CodeStart}}
{{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} limit
limit = {{Cl|_COMMANDCOUNT}}
{{Cl|FOR}} i = {{Text|1|#F580B1}} {{Cl|TO}} limit
     {{Cl|PRINT}} {{Cl|COMMAND$}}(i)
     {{Cl|PRINT}} {{Cl|COMMAND$}}(i)
{{Cl|NEXT}}
{{Cl|NEXT}}
Line 29: Line 30:


{{PageNavigation}}
{{PageNavigation}}
[[Category:Latest]]

Latest revision as of 21:48, 20 March 2023

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.
  • In C, this function would generally be regarded as 'argc' when the main program is defined as the following: int main(int argc, char *argv[])


Examples

Example: The code below gets the number of parameters passed to our program from the command line with _COMMANDCOUNT:

limit = _COMMANDCOUNT
FOR i = 1 TO limit
    PRINT COMMAND$(i)
NEXT
Explanation: If we start ThisProgram.exe from the command window with ThisProgram -l "loadfile.txt" -s "savefile.txt", the _COMMANDCOUNT would be 4, "-l", "loadfile.txt", "-s", "savefile.txt" command arguments passed to the program, which we could then read separately with COMMAND$(n).


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link