Liberty BASIC Help Online

CommandLine$
CommandLine$
 
Description:
This special variable contains any switches that were added when Liberty BASIC was started.  This is especially useful in applications executing under the runtime engine.  It allows a tokenized program to receive information upon startup and act upon that information.  The CommandLine$ variable can be parsed in the same way as other strings to retrieve the information.  One way to extract information from the CommandLine$ is with INSTR().  The WORD$() and VAL() functions can also be used to evaluate the contents of CommandLine$See the examples and explanations below.
 
Usage:
 
In this example the program checks CommandLine$ for the existence of the word "red" and if it is there, the program executes a color command:
 
'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
 
To call this program from another program as a TKN or EXE, or to run the EXE by using the RUN button in Windows:
 
run "commandlinetest1.tkn red"
or
run "commandlinetest1.exe red"
'the CommandLine$ variable will contain "red"
 
 
Multiple parameters in CommandLine$
 
The CommandLine$ may be parsed using the WORD$() function as well.  In the following example, the program checks for three colors to use in a graphics window.
 
'commandlinetest2.bas
'
'program to be tokenized
'to commandlinetest2.tkn
'and used with runtime engine
'commandlinetest2.exe
 
open "CommandLine$ Test" for graphics as #win
print #win, "trapclose [quit]"
print #win, "down"
 
if word$(CommandLine$, 1) <> "" then
fillColor$ = word$(CommandLine$,1)
    print #win, "fill ";fillColor$
end if
 
if word$(CommandLine$, 2) <> "" then
backColor$ = word$(CommandLine$,2)
    print #win, "backcolor ";backColor$
end if
 
if word$(CommandLine$, 3) <> "" then
Color$ = word$(CommandLine$,3)
    print #win, "color ";Color$
end if
 
print #win, "size 5"
print #win, "place 10 20"
print #win, "boxfilled 100 110"
print #win, "flush"
wait
 
[quit]
close #win : end
 
To call this program from another program as a TKN or EXE, or to run the EXE by using the RUN button in Windows:
 
run "commandlinetest2.tkn red yellow blue"
or
run "commandlinetest1.exe red yellow blue"
'the CommandLine$ variable will contain "red yellow blue"
 
Numbers and CommandLine$
The information contained  and used in CommandLine$ can be anything that can be contained in a string.  If numbers are required, then use the VAL() function to extract them.
 
first$ = word$(CommandLine$,1)
firstval = val(first$)
 
Suggestions for using CommandLine$
The CommandLine$ could contain a filename which the program would open and load into a texteditor.  The 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.
 
 


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/