CommandLine$

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

If you use parameters or switches in a command line statement, those parameters will be contained in the special variable CommandLine$. This is useful when running a .tkn file under the runtime engine. To check for the parameters, you inspect the CommandLine$ in your called program for the existence of any switches or parameters.

Usage

From the JB Help file, here is an example that will fill the background of a graphics window with the color "red" when opening. Notice how the CommandLine$ is inspected with the instr() function to see if it contains the parameter "red".

'commandlinetest1.bas
'
'program to be tokenized
'to commandlinetest1.tkn
'and used with runtime engine
'commandlinetest1.exe

open "CommandLine$ Test" for graphics as #win
print #win, "trapclose [quit]"

'convert to lower case for evaluation:
CommandLine$ = lower$(CommandLine$)

if instr(CommandLine$, "red") > 0 then
    print #win, "fill red; flush"
end if

wait

[quit]
close #win : end

Syntax

To call this program, you might use this syntax:

  1. run "commandlinetest1.tkn red"

or

  1. run "commandlinetest1.exe red"

Hints

  • Multiple Parameters.Of course, your command line could contain more than one parameter. If so, you can use the WORD$() function to extract each word. For example:
if word$(CommandLine$, 1) = "red" then
    print #win, "fill red; flush"
end if
  • Parsing Numbers. The information in CommandLine$ can be anything that could be in a string. If you need to extract a number from the string, use the VAL() function:
first$ = word$(CommandLine$, 1)
firstVal = val(first$)
  • Suggestions for Use. From the Help file once again:
The variable CommandLine$ could contain a filename which the program would open and load into a texteditor. The variable CommandLine$ could contain numbers to be used in calculations. As in the examples above, it could contain colors that determine the look of a window.

Useful Procedures

' Place a useful function using this keyword here