BASIC09 Command Reference l 11
LEN
Returns the length of a string
Syntax:
LEN(string)
Function:
Returns the number of characters in a string.
Counts blanks or spaces as characters.
Parameters:
string A literal string or a variable containing string
characters.
Examples:
PRINT LEN("AHCDEFGHIJKLM")
PRINT LEN(NAME$)
NAME$ = "JOE"
ADDRESS$ _ "2244 LANCASTER"
TOTALLEN = LEN(NAME$)+LEN(ADDRESS$)
Sample Program:
The following procedure uses LEN to determine which name in a
list is longest.
PROCEDURE longname
ODIM NAMES,LNAME:STRING; LONGEST,LENGTH:INTEGER
pNAMES-"" \LNAME="" \LENGTH=8 \LONGEST=0
pFOR T=1 TO 18
DREAD NAMES
pLENGTH-LEN(NAMES)
OF LONGEST(LENGTH THEN
OLONGEST=LENGTH _
pLNAME=NAMES
DENDIF
ONEXT T
OPRINT "The longest name is "; LNAME; " with "; LONGEST; " characters,"
pEND
ODATA "Joe Blonski","Mike Marvel","Hal Skeemish","Fred Laungly"
pDATA "Jane Misty","Wendy Paston","Martha Upshong","Jacqueline Rivers"
pDATA "Susy Reetmore","Wilson Creding"
11-77
BASIC09 Reference
LET
Assigns a variable's value
Syntax:
[LET] variable = expression
Function:
Assigns a value to a variable. BASIC09 does not
require the LET statement to assign values but does accept it
in order to be compatible with versions of BASIC that do
require it.
Parameters:
variable
The variable to which you want to assign a
value.
expression Either a numeric or string constant or a
numeric or string expression.
Notes:
· The result of the LET expression must be of the same type
as, or compatible with, the variable in which it is stored.
· BASIC09's assignment function accepts either = or : = as
assignment operators. The : = form helps to distinguish
assignment operations from comparisons (test for equality)
and is compatible with Pascal programming.
Use BASIC09's assignment function to copy entire arrays or
complex data structures to another array or complex data
structure. The data structures do not need to be of the
same type or
shape,
but the size of the destination structure must be the same as or larger than the source structure. This means the assignment function can perform
unusual type conversions. For example, you can copy a
string variable of 80 characters into a one-dimensional
array of 80 bytes.
11-78
BASIC09 Command Reference l 11
Examples:
LET A = 5
LET A :=
H
ANSWER = A * H
LET NAME$ :_ "JOE"
NAME $ = FIRSTNAME$ + " " + LASTNAME$
Sample Program:
This procedure uses LET to assign a random value to the variable R.
PROCEDURE getint
DDIM T: INTEGER
OFOR T=1 TO 1 0
OLET R=RNDC50)-25
OPRINT R,INTCR)
ONEXT T
REND
11-79
BASIC09 Reference
LNOT
Performs a logical NOT on a number
Syntax: LNOT(value)
Function:
Performs the logical NOT function on an integer or
byte type number. The operation involves a bit-by-bit logical
complement operation of the number you specify. For instance,
if value is 188, the logic looks like this:
188 Decimal = 10111100 Binary
NOT 10111100
= 01000011
01000011 Binary = 67 Decimal
LNOT changes each bit in a binary number to its complementary binary value all 1 values become 0 and all 0 values
become 1. LNOT returns an integer result; it is not a Boolean
operator.
Parameters:
value Any decimal or hexadecimal integer or byte
number. Precede hexadecimal numbers with
$.
Examples:
PRINT LNOT(88)
A = LNOT(B)
A = LNOT($44)
Sample Program:
This procedure uses one byte (contained in the variable STORAGE) to indicate the results of eight questions. Each bit in the
byte indicates a Yes or No answer (Yes =1 and No = 0). The combination logic of LAND and LNOT masks the byte X so that it
affects only the appropriate bit of STORAGE to set it to 0 if the
answer is No. LOR sets the appropriate bit to 1 if the answer is
Yes. The procedure operates in conjunction with the LXOR sample program.
11-80
BASIC09 Command Reference l 11
PROCEDURE questions
pDIM QUESTION;STRINGf681; T;INTEGER; X,STORAGE;BYTE
ODIM ANSWER;STRINGt1l
OX=1
OFOR T=1 TO 8
OREAD QUESTION
OPRINT QUESTION; " (Y/N)?
";
OGET #O,ANSWER
OPRINT
OF ANSWER="y" OR ANSWER="Y" THEN
OSTORAGEzLOR(STORAGE,X) (* Answer is yes, set bit to 1,
DELSE
OSTORAGEsLAND(STORAGE,LNOT(X)) (* Answer is no, set bit to 0,
REND I F
OX=X*2
ONEXT T
OPRINT STORAGE
ORUN summary(STORAGE)
REND
ODATA "Do you have more than one Color Computer"
ODATA "Do you use your Color Computer for games"
ODATA "Do you use your Color Computer for word processing"
ODATA "Do you use your Color Computer for business applications"
ODATA "Do you use your Color Computer at home"
ODATA "Do you use your Color Computer at the office"
ODATA "Do you use your Color Computer more than two hours a day"
ODATA "Do you share your Color Computer with others"
BASIC09 Reference
LOG
Returns natural logarithm
Syntax:
LO G(n um ber)
Function:
Computes the natural logarithm of a number that
is greater than zero. BASIC09 returns the logarithm as a real
type result.
Parameters:
number Any integer, byte, or real number.
Examples:
PRINT LOG(3 . 1 41 59)
LOGVALUE = LOG(88/PI)
Sample Program:
This procedure calculates the natural log and the log to base 10
of the values 1-7.
PROCEDURE logs
ODIM NUM,T:INTEGER
OFOR T=1 TO 7
OPRINT "The LOG of "; T; " to the natural base =
"· LOG(T)
OPR I NT "The LOG of "; T; " to base 1 0 = ";
LOG10(T)
OPRINT
ONEXT T
REND
11-82
BASIC09 Command Reference l 11
LOG10
Returns base 10 logarithm
Syntax:
LOG 10(n um ber)
Function:
Calculates the base 10 logarithm of a number.
BASIC09 returns the logarithm as a real number.
Parameters:
number Any byte, integer, or real value.
Examples:
PRINT LOG1 0 ($ 45
PRINT LOG1 0 (A
PRINT LOG10(A/12)
Sample Program:
This procedure calculates the natural log and the log to base 10
of the values 1-7.
PROCEDURE logs
ODIM NUM,T:INTEGER
pFOR T=1 TO 7
OPRINT "The LOG of "; T; " to the natural base =
"· LOG(T)
OPR I NT "The LOG of "; T; " t o base 1 0 = ";
LOG10(T)
pPRINT
ONEXT T
OEND
11-83
BASIC09 Reference
LOOP/ENDLOOP
Establishes/Closes a loop
Syntax: LOOP
statements)
ENDLOOP
Function:
Establishes a loop in which you can install EXITIF
tests at any location. The LOOP and ENDLOOP statements
define the body of the loop. EXITIF tests for a condition
which, if TRUE, causes alternate actions, the transfer of procedure execution to another routine, or both.
If you do not include an EXITIF statement, the loop cannot
terminate.
Parameters:
statements)
One or more procedure lines to execute within
the loop.
Examples:
LOOP
COUNT = COUNT+1
EXITIF COUNT > 100 THEN
DONE = TRUE
ENDEXIT
PRINT COUNT
X=COUNT/2
ENDLOOP
INPUT X,Y
LOOP
PRINT
EXITIF X<0 THEN
PRINT "X became 0 first"
END
ENDEXIT
X = X-1
EXITIF Y=0 THEN
PRINT "Y became 0 first"
11-84
BASIC09 Command Reference / 11
END
ENDEXIT
,, Y=Y-1
ENDLOOP
Sample Program:
This procedure simulates a gambling machine that awards cash
returns depending on a random selection of kinds of fruits. You
begin with a stake of $25 and win or lose according to random
selections of the procedure.
The program uses LOOP/ENDLOOP to keep operating until you
run out of cash.
PROCEDURE bandit
ODIM FRUIT1,FRUIT2,FRUIT3,STAKE:INTEGER;
FRUITC10):STRINGLGJ
pSTAKE=2S
OPRINT \ PRINT "You have $"; STAKE; " to play
with."
,/"` pFOR T=1 TO 10
DREAD FRUITCT)
ONEXT T
SLOOP
OFRUIT1=RNDC9)+1 \FRUIT2=RNDC9)+1 \FRUIT3=RNDC9)+1
pPRINT FRUITCFRUIT1); " "; FRUITCFRUIT2); " ";
FRUITCFRUIT3)
CIF FRUITCFRUIT1)=FRUITCFRUIT2) AND FRUITCFRUIT1)=
FRUITCFRUIT3) THEN
OSTAKE=STAKE+10
OELSE
EIF FRUITCFRUIT1)=FRUITCFRUIT2) OR FRUITCFRUIT2)=
FRUITCFRUIT3) THEN
0STAKE=STAKE+2
OELSE
pIF FRUITCFRUIT1)=FRUITCFRUIT3) THEN
0STAKE=STAKE+1
OELSE STAKE=STAKE-1
[1END I F
REND I F
DENDIF
pEX ITIF STAKE<1 THEN
pPRINT
pPRINT "You're Busted ...Hetter go home."
11-85
BASIC09 Reference
PROCEDURE questions
ODIM QUESTION:STRINGC60J; T:INTEGER;
X,STORAGE:HYTE
ODIM ANSWER:STRINGf1J
OX=1
OFOR T=1 TO 8
DREAD QUESTION
OPRINT QUESTION; " (Y/N)? ";
OGET *O,ANSWER
OPRINT
OIF ANSWER="y" OR ANSWER="Y" THEN
OSTORAGE=LORCSTORAGE,X)
OELSE
OSTORAGE=LANDCSTORAGE,LNOTCX))
OEND I F
OX=X*2
ONEXT T
OPRINT STORAGE
ORUN summaryCSTORAGE)
REND
ODATA "Do you have more than one Color Computer"
ODATA "Do you use your Color Computer for games"
ODATA "Do you use your Color Computer for word
processing"
ODATA "Do you use your Color Computer for business
applications"
ODATA "Do you use your Color Computer at home"
ODATA "Do you use your Color Computer at the
office"
ODATA "Do you use your Color Computer more than
two hours a day"
ODATA "Do you share your Color Computer with
others"
11-86
BASIC09 Command Reference l 11
LXOR
Returns logical XOR of two numbers
Syntax: LXOR(valuel, valueZ
Function:
Performs the logical XOR function on two-byte, or
integer-type, values. For instance, if you LXOR the numbers 5
and 6 the logic is like this:
Decimal 6 = Binary 0110
0101
= 0011 = 3 Decimal
If one bit or the other bit in the evaluation is 1, but not both,
LXOR returns a result of 1. Otherwise, LXOR returns a
result of 0.
Parameters:
valuel A byte or integer number.
valw2 A byte or integer number.
Examples:
PRINT LXOR(11,12)
PRINT LXOR($20,$FF)
Sample Program:
The following program summarizes the results of the sample
program for LOR. The LOR program stored the answers to eight
questions in a single byte. This procedure reads the byte and
displays appropriate comments. LXOR checks to see if two of the
answers are "yes" or "no."
11-87
BASIC09 Reference
pENDEXIT
pPRINT "Your Stake
i5
now $"; STAKE; "."
pPRINT
pPRINT
pINPUT "Pre55 ENTER to pull again...",Z$
OENDLOOP
pEND
pDATA "ORANGE","APPLE","CHERRY","LEMON","BANANA"
ODATA "PEAR", "PLUM","PEACH","GRAPE","APRICOT"
11-88
BASIC09 Command Reference l I Z
LOR
Returns logical OR of two numbers
Syntax:
LOR(valuel, valueZ
Function:
Performs the logical OR function on a byte- or
integer-type value. The operation involves a bit-by-bit logical
OR operation on two values. For instance, if you LOR the
numbers 5 and 6, the logic is like this:
Decimal 5 = Binary 0101
Decimal 6 = Binary 0110
0101
OR 0110
= 0111 = 7 Decimal
If one bit or the other bit is 1, LOR returns a result of 1.
Otherwise, LOR returns a result of 0.
Parameters:
valuel A byte or integer number.
value2 A byte or integer number.
Examples:
PRINT LOR(11,12)
PRINT LORC$20,$FF)
Sample Program:
This procedure stores the answers to eight "yes" or "no" questions in one byte, named STORAGE. If you answer "yes" to a
prompt, the procedure sets a corresponding bit to 1. If you
answer "no" to a prompt, the procedure sets a corresponding bit
to 0. The procedure uses LOR to set bits to 1 by masking all bits
except the one it needs to set. The procedure operates in conjunction with the LXOR sample program.
11-89
BASIC09 Reference
PROCEDURE summary
ODIM T: INTEGER; A,H,X,TEST,TEST2:HYTE; SUMMARY:
STRINGL501
OPARAM STORAGE:HYTE
DA=0 \H=0
OPRINT \ PRINT
OPRINT "The following is a summary of the
questionnaire answers:"
OPRINT
OPRINT "The surveyee: "
OX=1
OFOR T=1 TO 8
OTEST=LANDCSTORAGE,X)
DREAD SUMMARY
OIF TEST>0 THEN
OPR I NT TAHC 1 0) ; SUMMARY
REND I F
OX=X*2
ONEXT T
OIF LANDCSTORAGE,128)>0 THEN
DA =1
REND I F
OIF LANDCSTORAGE,64)>0 THEN
OB =1
REND I F
OTEST2=LXORCA,H)
DI F TEST2=1 THEN
OPRINT "This computer owner either uses the
computer"
OPRINT "more than two hours a day or shares it
with others."
OPRINT "This is a heavy use situation."
OENDIF
OTEST2=LANDCA,H)
DI F TEST2=1 THEN
OPRINT "This computer user uses the computer more
than two" _
OPRINT "hours per day and shares it with others.
This is a"
OPRINT "super heavy use situation."
DENDIF
REND
ODATA "Uses more than one computer"
ODATA "Plays games"
11-90
BASIC09 Command Reference l 11
pDATA
"Uses the computer for word proce55ing"
pDATA
"U5e5 the computer for bu5ine55"
ODATA
"Keeps a Color Computer at home"
ODATA
"Keeps a Color Computer at the office"
ODATA
"Uses the computer more than two hours a
day"
ODATA
"Shares the computer with others"
BASIC09 Reference
MID$
Returns characters from within a string
Syntax:
MID$(string,begin,length)
Function:
Returns a substring
length
characters long, beginning at
begin.
Use MID$ to "take apart" a string consisting
of a number of elements.
Parameters:
string
A sequence of string type characters or a
string type variable.
begin
The position (an integer value) in
string of
the
first character to retrieve.
length
The number of characters you want to retrieve.
Examples:
NAME$ = "JONES, JOHN M."
LASTNAME$ = MID$(NAME$,8,6)
FIRSTNAME$ = MID$(NAME$,1,S)
INITIAL$ = MID$(NAME$,1S,2)
Sample Program:
This procedure reverses a word or phrase you type. MID$ reads
each character in your phrase from the end to the beginning.
PROCEDURE reverse
ODIM PHRASE:STRING; T,HEGIN:INTEGER
OPRINT "Type a word or phrase you want to
reverse:";
OPRINT
DINPUT PHRASE
OHEGIN=LEN(PHRASE)
DPRINT "This is how your phrase looks backwards:"
OFOR T=BEGIN TO 1 STEP -1
OPRINT MID$(PHRASE,T,1);
ONEXT T
OPRINT
REND
11-92
BASIC09 Command Reference l 11
MOD
Returns modulus of a division
Syntax:
MOD(numberl,numberZ
Function:
Returns the modulus (remainder) of a division.
MOD divides
numberl
by
number2
and calculates the remainder. You can use MOD to put a limit on a numeric variable.
For instance, regardless of the value of X, MOD(X,3) produces
numbers only in the range 0 through 2. MOD(X,5) produces
numbers only in the range of 0 through 4.
You can use MOD to cause repeating sequences. For instance,
in a loop, MOD(X,3) produces a repeating sequence of 0, 1, 2,
where X increases by 1 in each step of the loop.
Parameters:
numberl A
byte, integer or real number dividend.
number2 A
byte, integer or real number divisor.
Examples:
PRINT MOD(99,S)
r
11-93
BASIC09 Reference
Sample Program:
This procedure uses MOD to execute repeatedly routines that
display asterisks on the screen. There are eight subroutines that
the MOD function selects over and over through 100 passes.
PROCEDURE
5tardown
pDIM T: INTEGER
OSHELL "TMODE -PAUSE"
pFOR T=1 TO 1 0 0
pON MODCT,8)+1 GOSUB 10,20,30,40,50,60,70,80
ONEXT T
OSHELL "TMODE PAUSE"
pE N D
1 0pPR I NT USING "S1 0"" , "*" RETURN
20pPRINT USING "S10"","**" \ RETURN
300PRINT USING "S10^","***" \ RETURN
40pPRINT USING "S10^","****" \ RETURN
50pPRINT USING "S10"","*****" \ RETURN
60pPRINT USING "S10^","****" \ RETURN
70pPRINT USING "S10^","***" \ RETURN
800PRINT USING "S10^","**" \ RETURN
OEND
11-94
BASIC09 Command Reference l 11
NEXT
Causes repetition in a FOR loop
Syntax: FOR
variable = init val TO end val
[STEP
value]
[procedure statements]
NEXT variable
Function:
NEXT forms the bottom end of a FOR/NEXT loop.
Any program statements between FOR and NEXT are executed once for each repetition of the loop, from the initial
value to end value.
Parameters:
variable
Any legal numeric variable name.
init val
Any numeric constant or variable.
end val Any numeric constant or variable.
value
Any numeric constant or variable.
procedure
Procedure lines you want to execute within
statements the loop.
For more information, see FOR/NEXT/STEP.
11-95
BASIC09 Reference
NOT
Returns the complement of a value
Syntax: NOT(value)
Function:
Returns the logical complement of a Boolean value
or expression.
Parameters:
value A Boolean value (True or False), or an expres
sion resulting in a Boolean value.
Examples:
DIM TEST:HOOLEAN
WHILE NOT(TEST) DO
A=A+1
TEST=A=H
ENDWHILE
Sample Program:
This procedure redirects the current directory listing to a file
named Dirfile. It then opens Dirfile and reads the contents, displaying each line on the screen. It uses NOT in a WHILE/ENDWHILE loop to make sure that the end of the file has not been
reached before trying to read another entry.
PROCEDURE readfile
ODIM A:STRINGL80J
ODIM PATH:HYTE
OSHELL "DIR > dirf ile"
DOPEN #PATH,"dirfile":READ
EWHILE NOT EOF(#PATH) DO
DREAD #PATH,A
OPRINT A
DENDWHILE
OCLOSE #PATH
FEND
11-96
BASIC09 Command Reference l 11
ON ERROR/GOTO
Establishes an error trap
Syntax: ON ERROR [GOTO linenum]
Function:
Sets an error trap that transfers control to the specified line number in a procedure. This lets your program
recover from an error and continue execution. To use these
commands, your program must have at least one numbered
line-the line to branch to in the event of an error.
Parameters:
linenum
The line to which you want BASIC09 to
branch should an error occur.
Notes:
0
ON ERROR GOTO is effective only with non-fatal, runtime errors. If such an error occurs without a preceding ON
ERROR GOTO statement, BASIC09 enters the DEBUG
mode. You must specify ON ERROR GOTO before an error
occurs.
0
You turn on error trapping by specifying ON ERROR
GOTO linenum. You
turn off error trapping by specifying
ON ERROR without a line number.
~ Use ON ERROR GOTO with the ERR function (that
returns the code of the last error) to specify a particular
action for a particular error. You can also use ERROR to
simulate an error to test error trapping. For more information on this, see ERROR.
11-97
BASIC09 Reference
Examples:
ODIM FILENAME:STRING
ODIM PATH: INTEGER
100INPUT "Name of file to create? ",FILENAME
DON ERROR GOTO 100
OCREATE #PATH,FILENAME:UPDATE
REND
1000PRINT "That file already exi5t5...plea5e
choose another name..."
OGOTO 1 0
REND
Sample Program:
If you created a directory file with the GET sample program,
you can use this procedure to delete files from the original directory using key characters. For instance, you might type XX as
key characters. This means that any filename containing the
character group XX is deleted. You can select any key characters
you wish, but be sure they apply only to files you want to
delete.
If you want to delete all the files in the directory, type an asterisk (*) when asked for key characters.
This procedure uses ON ERROR to let the procedure continue,
even if a directory entry cannot be deleted if an entry is a subdirectory. Without the ON ERROR function, the procedure
would produce an error and cease execution when it tried to
delete a subdirectory.
PROCEDURE purge
OREM Use caution with this procedure
OREM He Sure to Specify key characters
OREM that exist only in the files you
OREM want to delete!
ODIM PATH: INTEGER -
ODIM NAMEC100):STRING
ODIM WILDCARD:STRING
OX=0
DOPEN #PATH,"dirfile":READ
OWHILE NOTCEOFC#PATH)) DO
OX=X+1
DREAD #PATH,NAMECX)
11-98
BASIC09 Command Reference l 11
pENDWHILE
pFOR T=1 TO X
pPRINT NAMECT),
pNEXT T
pINPUT "Wildcard Characters...",WILDCARD
pFOR T=1 TO X
pON ERROR GOTO 100
pIF SUHSTRCWILDCARD,NAMECT))>0 OR WILDCARD="*"
THEN
pPRINT "DELETING
pDELETE NAMECT)
pEND I F
10ONEXT T
pEND
1 00pPR I NT "*Q*Q*QERROR,p"; NAMECT) ;
deleted ...continuing.
pGOTO 1 0
pEND
NAMECT); " "
"pcannot be
BASIC09 Reference
ON/GOSUB
Jumps to subroutine on a
specified condition
Syntax: ON pos GOSUB
linenum [,linenum,...]
Function:
Transfers procedure control to the line number
located at position pos in the list of line numbers immediately
following the GOSUB command. For example, if pos equals 1,
BASIC09 branches to the first line number it encounters in
the list. If pos equals 2, BASIC09 branches to the second line
number it encounters in the list. If pos is greater than the
number of items in the list, execution continues with the next
command line. To use ON/GOSUB you must have numbered
lines to match the line numbers in your list. End the routines
accessed by ON/GOSUB with a RETURN statement.
Parameters:
pos An integer value pointing to a line number in
a list of line numbers.
linenum Any numbered line in the procedure.
Examples:
PRINT "You can now: C1) End the program C2) Print
the re5ult5"
PRINT " C3) Try again C4) Start
a new program"
INPUT "Type the letter of your-choice: ",CHOICE
ON CHOICE GOSUH 100, 200, 300, 400
11-100