Difference between revisions of "COMMAND$"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 13: Line 13:




''Example:'' Program A [[RUN|runs]] a program with a parameter following the filename:  
''Example:'' Compile both programs. ProgramA [[RUN]]s ProgramB with a parameter passed following the filename:  
{{CodeStart}}
{{CodeStart}}
{{Cl|RUN}} "ProgramB.exe fs"  
{{Cl|LOCATE}} 12, 36: {{Cl|PRINT}} "ProgramA"
 
{{Cl|LOCATE}} 23, 25: {{Cl|PRINT}} "Press any key to run ProgramB"
K$ = {{Cl|INPUT$}}(1)
{{Cl|RUN}} "ProgramB FS" 'pass FS parameter to ProgramB in QB64
 
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
: ''Program B'' checks for fullscreen parameter pass in QB64.  
: ''ProgramB'' checks for fullscreen parameter pass in QB64 and goes full screen.  
{{CodeStart}}
{{CodeStart}} '' ''
parameter$ = {{Cl|COMMAND$}}
{{Cl|LOCATE}} 12, 36: {{Cl|PRINT}} "ProgramB"
{{Cl|IF}} {{Cl|UCASE$}}({{Cl|LEFT$}}(parameter$, 2)) = "FS" THEN {{Cl|_FULLSCREEN}} 'parameter already uppercase in Qbasic
parameter$ = {{Cl|UCASE$}}({{Cl|COMMAND$}})
{{Cl|LOCATE}} 20, 33: {{Cl|PRINT}} "Parameter = " + parameter$
{{Cl|IF...THEN|IF}} {{Cl|LEFT$}}(parameter$, 2) = "FS" {{Cl|THEN}} {{Cl|_FULLSCREEN}} 'parameter changes to full screen
 
{{Cl|END}} '' ''
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}                              Parameter = FS.EXE
{{OutputEnd}}





Revision as of 09:18, 7 January 2011

The COMMAND$ function returns the DOS commandline arguments passed when a program is run.


Syntax: variable$ = COMMAND$


  • The string return value is any parameter following the filename in a RUN or command line statement.
  • Qbasic returns uppercase STRING parameters no matter what case they were sent originally.
  • QB64 does not require or return all uppercase values so keep that fact in mind when checking parameters passed!
  • Useful when the programmer wants to add options to the command line of a program for later use by another program.
  • COMMAND$ was not available in QuickBasic versions below 4.0


Example: 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 END

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

LOCATE 12, 36: PRINT "ProgramB" parameter$ = UCASE$(COMMAND$) LOCATE 20, 33: PRINT "Parameter = " + parameter$ IF LEFT$(parameter$, 2) = "FS" THEN _FULLSCREEN 'parameter changes to full screen END

Parameter = FS.EXE


See also:




Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page