FALSE Assi Boolean value

Syntax: variable =FALSE

Function: FALSE is a Boolean function that always returns False. You can use FALSE and TRUE to assign values to Boolean variables.

Parameters: None

Examples:

DIM TEST:BOOLEAN
TEST-FALSE

Sample Program:

The procedure uses a Boolean variable to store True or False, depending on whether you answer some questions correctly or incorrectly.

PROCEDURE quiz ODIM REPLY,VALUE:BOOLEAN; ANSWER:STRINGf1J; QUESTION:STRINGL801 OFOR T-1 TO S OREAD QUESTION,VALUE OPRINT QUESTION OPRINT "CT) = TRUE0000000CF) = FALSE" OPRINT "Select T or F:00"; OGET x1,ANSWER OIF ANSWER="T" THEN OREPLY=TRUE OELSE OREPLY=FALSE OEND I F OIF REPLY=VALUE THEN OPRINT \ PRINT "That's Correct ...Good Show!" OELSE OPRINT "Sorry, you're wrong ...Better Luck next time." OEND I F OPRINT \ PRINT \ PRINT


BASIC09 Reference

i 1.s2

ONEXT T ODATA "In computer talk, CPU stands for Central Packaging Unit.", FALSE ODATA "The actual value of 64K is 6SS36 bytes.",TRUE ODATA "The bits in a byte are normally numbered 0 through 7?",TRUE ODATA "BASIC09 has four data types.",FALSE ODATA "The LAND function is a Boolean type operator.",FALSE REND


FIX Round a real number

Syntax: FIX(value)

Function: Rounds a real number to the nearest whole number and converts it to an integer-type number. Fix performs a function that is the opposite of the FLOAT function.

Parameters:

value Any real number.

Examples:

A=RND(1 0 )
PRINT FIX(A)

Sample Program:

This procedure displays the FIXed values of seven constants.

PROCEDURE printfix
OPRINT FIX(1.2)
OPRINT FIX(1.3)
OPRINT FIX(1.5)
OPRINT FIX(1.8)
OPRINT FIX(99.566666)
OPRINT FIX(50.1 )
OPR I NT FIX (.7654321 )
OPRINT FIX(-12.44)
OPRINT FIX(-9.99)
REND

11-53
BASIC09 Reference

FLOAT Convert from integer or byte to real

Syntax: FLOAT(value)

Function: Converts an integer- or byte-type value to real type. FLOAT performs a function that is the opposite of the FIX function.

Parameters:

value An integer- or byte-type number.

Examples:

DIM TEST: INTEGER
TEST=44
PRINT FLOAT(TEST)/3

Sample Program:

This procedure uses FLOAT to produce a real number result of an inch to centimeter conversion.

PROCEDURE convert
ODIM T: INTEGER; MEASURE:STRINGL11J
OFOR T=1 TO 1 0
DI F T=1 THEN
OMEASURE="centimeter "
OELSE
pMEASURE="centimeters"
DENDIF

OPRINT T; " "; MEASURE;
" inches."
ONEXT T
pEND

"; FLOATCT)*.3937;

11-54
BASIC09 Command Reference l 11

FOR/NEXT/STEP Establish a loop

Syntax: FOR variable = init val TO end val [STEP value] [procedure statements] NEXT variable

Function: Establishes a procedure loop that lets BASIC09 execute one or more procedure statements a specified number of times. The variables you use can be either integer or real type and can be negative, positive, or both. Loops using integer values execute faster than loops using real values.


BASIC09 executes the lines following the FOR statement until it encounters a NEXT statement. Then it either increases or decreases the initial value by one (the default) or by the value

given STEP.
Parameters:
Variable Any legal numeric variable name.
init val Any numeric constant or variable.
end Ual Any numeric constant or variable.
Value Any numeric constant or variable.
procedure Procedure lines you want to be executed
statements within the loop.

Notes:



BASIC09 Reference

When execution reaches the NEXT statement in a positive stepping loop, and the step value is less than or equal to the end value, BASIC09 branches back to the line after FOR and repeats the process. When the step value is greater than the end value, BASIC 09 transfers execution to the statement following the NEXT statement.


    0 When execution reaches the NEXT statement in a negative stepping loop, and the step value is greater than or equal to the end value, BASIC09 branches back to the line after FOR and repeats the process. When the step value is less than the end value, execution continues following the NEXT statement.


Examples:

FOR COUNTER = 1 to 100 STEP .5 PRINT COUNTER NEXT COUNTER

FOR X = 1 0 TO 1 STEP -1 PRINT X NEXT X

FOR TEST = A TO B STEP RATE PRINT TEST NEXT TEST

Sample Program:

This procedure uses two nested FOR/NEXT loops to produce a multiplication table.


PROCEDURE multable pPRINT USING "S45-",--MULTIPLICATION TABLE" OPR I NT pDIM I,J:INTEGER OFOR I=1 TO 9 pFOR J=1 TO 9 DIF J>1 THEN OPRINT I*J; TABCS*J); CIELSE PRINT I * J ; "~ "; DENDIF ONEXT J OIF I=1 THEN OPRINT ""

11-56
        BASIC09 Command Reference / 11


pPRINT '---_____________________________________

pEND I F
OPRINT
ONEXT I
REND

11-57
      BASIC09 Reference


      GET Read a direct-access file record


      Syntax: GET #path,varname


      Function: Reads a fixed-size binary data record from a file or device. Use GET to retrieve data from random access files.


      Although you usually use GET with files, you can also use it to receive data for any outputting device, such as a keyboard or another computer. By dimensioning a string variable to the length of input you want, you can use GET to read a specified number of keystrokes, then continue program execution without requiring ENTER to be pressed.


      Fbr information about storing data in random access files, see

' Chapter 8, "Disk Files." Also see PUT, SEEK, and SIZE.

      Parameters:


      path A variable name you choose in which BASIC09

      stores the number of the path it opens to the

      device you specify or one of the standard I/O

      paths (0, 1, or 2).

      varname The variable in which you want to store the

      data read by the GET statement.

      Examples:

      GET #PATH,DATA$

      GET #1,RESPONSE$

      GET #INPUT,INDEXCX)


      Sample Program:


      This procedure directs a directory listing to a file named Dirfile. GET then reads the file, one character at a time in order to determine which characters are valid filename character. The procedure creates a file containing all the filenames in the directory.


      11-58

BASIC09 Command Reference l 11

PROCEDURE filenames pDIM DIRECTORY,FILENAME:STRING; CHARACTER:STRINGt1J; FILES(125):STRINGf15J; PATH,COUNT,T:INTEGER pCOUNT=8 pFILENAME="" pFOR T=1 TO 125 0 initialize array elements to null. pFILES(T)="" pNEXT T pINPUT "Pathlist of directory to read...",DIRECTORY (* dir to copy. pON ERROR GOTO 18 pDELETE "dirfile" 0 if dirfile already exists, delete it. 18pON ERROR pSHELL "DIR "+DIRECTORY+' ) dirfile" 0 copy directory into file. pOPEN xPATH,"dirfile":READ (* open the file for reading. pREPEAT OREM Get characters from the file until the first carriage return - the beginning of the first filename. pGET xPATH,CHARACTER 0 get characters from the file. pUNTII CHARACTER=CHRS(13) OREM 20OLOOP pEXITIF EOF(xPATH) THEN pGOTO 288 0 quit when end of file. pENDEXIT OREM get a character from the file until it finds a. non-valid filename character. pGET xPATH,CHARACTER OREM pEXITIF CHARACTER<=" " OR CHARACTER>"z" THEN pGOTO 10 8 pENDEXIT pFILENAME=FILENAME+CHARACTER 0 build the filename. pENDL00P 188pWHILE NOT(EOF(xPATH)) DO pGET #PATH,CHARACTER 0 check for non-valid filename characters. pEXITIF CHARACTER" " AND CHARACTERS="z" THEN (* check if valid char, pCOUNT=COUNT+1 pFILES(COUNT)=FILENAME 0 store filename in array. pPRINT FILENAME, 0 display the extracted filename. pFILENAME="" 0 set variable to NULL. pFILENAME=FILENAME+CHARACTER 0 last character begins new filename. pGOTO 28 (* go get the rest of filename. pENDEXIT pENDWHILE 2000CLOSE #PATH

11-59
BASIC09 Reference

DELETE "dirfile" (# names are all in array so delete file.
pCREATE OPATH,"dirfile":WRITE (* create the file again.
OFOR T-1 TO COUNT
pWRITE OPATH,FILES(T) (* fill the file with individual filenames.
ONEXT T
pCLOSE #PATH
pPR I NT
pPRINT "0000000*The directory has "; COUNT; " entries."
OPRINTO"ppp0ppppThey are now stored in a file named Dirf ile."
pEND

11-60
                BASIC09 Command Reference 11


GOSUB/RETURN

Jump to subroutine/ Return from subroutine

Syntax: GOSUB linenumber

Function: Branches program execution to the specified line number.


BASIC09 lets you write programs with line numbers or without. You can also mix numbered and un-numbered lines within a single procedure. This means that, to use GOSUB, you need to number only the first line of the subroutine to which you want to branch.


Every subroutine you access with GOSUB must contain a RETURN statement. You can call a subroutine in this manner as many times as you want. When BASIC09 encounters the RETURN, it transfers program execution to the line following the GOSUB statement.


You can precede GOSUB with a test statement, such as IF or WHEN, that makes branching conditional.


You can nest GOSUB statements to any depth, depending on your computer's free memory.


Parameters:
linenumber The number of the line where procedure exe
cution is to continue.
Examples:
GOSUH 1 0 0
11-61
BASIC09 Reference

Sample Program:

The following procedure asks you for two numbers and an operator. It determines the line to jump to by the position of the operator in a table. GOSUB sends the procedure to execute the proper routine. RETURN sends the execution back to the main routine. To quit, enter a negative value.

PROCEDURE calc

ODIM NUM1,NUM2:REAL; OP:STRINGL1J; A:INTEGER 1 EI NPUT "NUMBER 1 "; NUM1

DIF NUM1 c0 THEN
pEND "THAT'S ALL"

pINPUT "NUMBER 2 ";NUM2 OINPUT "OPERATOR ";OP 0A=SUBSTRCOP,"+-*/"") 00N A GOSUB 10,20,30,40,50 pGOTO 1

1 00PR I NT NUM1 +NUM2 \ RETURN 200PRINT NUM1 -NUM2 \ RETURN 300PRINT NUM1 *NUM2 \ RETURN 400PRINT NUM1 /NUM2 \ RETURN 500PR I NT NUM1 NUM2 \ RETURN REND


11-11

11-62
BASIC09 Command Reference l 11

IF/THEN/ELSE/ENDIF

Vest a Boolean expression

Syntax: IF condition THEN linenumber
[ELSE
secondary action
ENDIF]

IF condition THEN action [ELSE secondary action] ENDIF

Function: Tests a Boolean expression and executes action if the expression is true. Optionally, the statements execute a secondary action if the expression is not true. Each IF statement must be accompanied by THEN. If action is a line number, you can omit the ENDIF statement. For instance, both of the following statements operate in the same manner:

IF T=5 THEN 10

IF T=5 THEN
GOTO 1 0
ENDIF

Parameters:

condition

A Boolean expression (produces True or False).

linenumber A line to which the procedure is to transfer
execution if condition is true.

action

secondary
action

One or more procedure statements to be executed if condition is true.

One or more procedure statements to execute if condition is false.

11-63
BASIC09 Reference

Examples:

IF AFB THEN 100

IF A<B THEN 100
ELSE
A=A-1
ENDIF

IF TEST=TRUE THEN
PRINT "The test i5 a 5ucce55..."
ENDIF

I F A < B THEN
PRINT "A i5 1e55 than B"
.ELSE
PRINT "B i5 1e55 than A"
ENDIF

Sample Program:

The following procedure is a purge procedure. Use it only with the GET Sample Program to delete one or more files from your current directory. .


The Filenames procedure (see GET) stores the current directory's-filenames in Dirfile. This procedure reads Dirfile, displays all the filenames, then asks you for a wildcard. Type in characters that identify a group of files you want to delete. The program deletes all files that contain, in the same order and case, the characters you type.


For instance, if you have four files named Test, File 1, Filet, and File3, and you type a wildcard of "File," the procedure deletes Filel, Filet, and File3, but does not delete Test. Delete all of the files in a directory by typing "*" as the wildcard.


Use this program carefully. Be sure you are in the right directory and that the wildcard characters you type are not contained in filenames other than the ones you want to delete. You might want to add a prompt to the procedure that lets you confirm each deletion before it happens.


11-64
BASIC09 Command Reference l 11

PROCEDURE purge ODIM PATH: INTEGER pDIM NAMEC100):STRING ODIM WILDCARD:STRING OX=0 DOPEN #PATH,"dirfile":READ OWH I LE NOTC EOF C #PATH)) DO pX=X+1 DREAD *PATH,NAMECX) OENDWHILE pFOR T=1 TO X OPRINT NAMECT), ONEXT T pINPUT "Wildcard Character5...",WILDCARD OFOR T=1 TO X pON ERROR GOTO 100 OIF SUHSTRCWILDCARD,NAMECT))>0 OR WILDCARD ="*" THEN

pPRINT "DELETING "; NAMECT); ODELETE NAMECT) OENDI F 1 0ONEXT T OEND

100[]PRINT "* * * ERROR * * * "; NAMECT) be deleted..continuing." OGOTO 1 0

" cannot

11-65
BASIC09 Reference

INKEY Read a keypress

Syntax: RUN INKEY(string)

Function: Reads a keypress, and stores the character of the key in the specified string variable.

Parameters:

          string is a string variable into which INKEY stores the character you press.


Examples:

DIM CHAR:STRINGL1J
CHAR=""
WHILE CHAR="" DO
RUN INKEY(CHAR)
ENDWHILE
PRINT ASC(CHAR)

11-66
BASIC 09 Command Reference l Il

Sample Program:

PROCEDURE Calculate OD I M CHAR : STR I NG L 1 J ODIM LOOKUP:STRINGf71 ODIM FIRST,SECOND:REAL ODIM FLAG:INTEGER OLOOKUP="+-*/"<>" 1 FLAG=0 \CHAR="" OPRINT "Enter the first number to evaluate. DINPUT FIRST OIF FIRST=0 THEN OGOTO 1 0 0 REND I F

OPRINT "Enter the Second number to evaluate..."; DINPUT SECOND OPRINT "Pre55 the key of the operator you want to use..."

OPRINT " + - * / w < > OWHILE CHAR="" DO ORUN INKEYCCHAR) DENDWHILE OPRINT

OFLAG=SUHSTRCCHAR,LOOKUP) DON FLAG GOTO 10,20,30,40,50,60,70 10 PRINT FIRST+SECOND \ GOTO 1 20 PRINT FIRST-SECOND \ GOTO 1 30 PRINT FIRST*SECOND \ GOTO 1 40 PRINT FIRST/SECOND \ GOTO 1 50 PRINT FIRST ^SECOND \ GOTO 1 60 PRINT FIRST<SECOND \ GOTO 1 70 PRINT FIRST>SECOND \ GOTO 1 100 PRINT "Procedure Terminated Due to 0 Input..." REND

11-67
BASIC09 Reference

INPUT Get data from a device path

Syntax: INPUT [#path,] [promp4] variable [,variable...]

Function: INPUT accepts input from the specified path. (The default is the keyboard.) When a procedure encounters INPUT, it displays a question mark and awaits data from the specified path. If you provide a string type prompt for INPUT, it displays the text of the prompt, rather than a question mark.


INPUT stores the data it collects in the variable you specify. The type of the receiving variable must match the type of data received.


Because INPUT sends data (the question mark prompt or the user-specified string prompt), it is really both an input and an output statement. This means that, if you use a path other than the standard input path, you should not use the UPDATE mode. If you do, the prompts produced by INPUT write to the file specified by the path number.


If the data received does not match the type of data INPUT expects, it displays the message:


    **INPUT ERROR - RETYPE**


followed by a new prompt. You must then enter the entire input line, of the correct type, to satisfy INPUT. For more information, see GET.


11-68
                BASIC09 Command Reference / 11


Parameters:

path Either a variable containing the path number,
or the absolute path number to the file or
device from which you want to receive input. If
you want to receive input from the keyboard,
do not include a path number.
prompt Text you type as a message to be displayed
when BASIC09 executes an INPUT statement.
variable The variable name in which you want to store
the data received by INPUT. The type of vari
able must match the type of input.
Examples:

INPUT NUMBER,NAME$,LOCATION
INPUT #PATH,X,Y,Z
INPUT "What is your selection: ";CHOICE

'~ INPUT #HOST,"What's your ID number? ",IDNUM

      Sample Program:


This procedure calculates the day of the week for a specified date. It asks you for the date using the INPUT command.

PROCEDURE weekday ODIM X,Y,D,M,CALC:INTEGER; DAY,MONTH:STRINGL2J; YEAR:STRINGL4J; WEEKDAY C7):STRINGL9J EDIM ANUM,BNUM,CNUM,DNUM,ENUM,FNUM,GNUM,HNUM, INUM:INTEGER OPRINT USING "S80 ","Day of the Week Program","For any year after 1 752" OPRINT OPRINT "Enter day (e.g. 08): "; \ INPUT DAY SPRINT " Enter month (e.g. 12): "; \ INPUT MONTH OPRINT " Enter year (e.g. 1986): "; \ INPUT YEAR DY=VALCYEAR) \M=VALCMONTH) \D=VALCDAY) OFOR X=1 TO 7 EREAD WEEKDAYCX) ONEXT X DANUM= I NTC .6+1 /M) OBNUM=Y-ANUM

                                11-69

BASIC09 Reference

OCNUM=M+12*ANUM
ODNUM=HNUM/ 1 0 0
DENUM=INTCDNUM/4)
OFNUM=INTCDNUM)
pGNUM-INTCS*HNUM/4)
OHNUM- I NTC 1 3* C CNUM+ 1) / S )
OINUM=HNUM+GNUM-FNUM+ENUM+D-1
OINUM-INUM-7*INTCINUM/7)+1
OPR I NT
pPRINT "The day of the week on "; M; "/"; D;
"/"; Y; " i5 ..."; WEEKDAY CINUM)
ODATA "Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday"
REND

11-?0
BASIC09 Command Reference l Il

INT Convert real number to whole number Syntax: INT( value)

Function: Converts a real number to a whole number by truncating any fractional part of the real number.

Parameters:

value Any negative or positive real number.

Examples:
PRINT INT(77.89) PRINT INTCNUM) PRINT INT(-8.12)

Sample Program:

The RND function produces real numbers. This procedure uses INT to convert the real RND output to integer values.

PROCEDURE integer
DIM T: INTEGER
pFOR T=1 TO 1 0
DR=RNDC50)-25
SPRINT R,INTCR)
pNEXT T
pEND

                                11-71

BASIC09 Reference

KILL Remove a procedure from memory

Syntax: KILL procedure

Function: Unlinks (removes) an external procedure from the BASIC09 procedure directory. If the procedure is not external, but resides in BASIC09's workspace, KILL has no effect.

Use KILL to remove auto-loaded (packed) procedures that are called by RUN or CHAIN. You can also use KILL with autoloading procedures as a method to overlay programs within BASIC09.

    Warning: Be certain you do not KILL an active procedure. Also be certain that when you use RUN and KILL together, that both statements use the same string variable that contains the name of the procedure to RUN and KILL.


Parameters:

procedure The name of the external procedure you want
to KILL. Procedure can either be a name or a
variable containing the procedure name.
Examples:

PROCEDURENAME$ _ "AVERAGE"
RUN PROCEDURENAME$
KILL PROCEDURENAME$

INPUT "Which test do you want to run? ",TEST$
RUN TEST$
KILL TESTS

11-72
                BASIC09 Command Reference / 11


Sample Program:

This procedure calls a procedure named Show to display ASCII values on the screen. When it no longer needs the Show procedure, it removes Show from memory using KILL.

PROCEDURE produce
ODIM T,U:INTEGER
ODIM NUM,NUM1,NUM2,TAHLE,PROCNAME:STRING
OPROCNAME-SHOW
OTAHLE-"123456789AHCDEF"
OFOR T-8 TO 15
OFOR U-1 TO 15
ONUM1-MIDS(TAHLE,T,1)
ONUM2=MIDS(TAHLE,U,1)
ONUM=NUM1+NUM2 (* parameter to pass to Show.
ORUN PROCNAME(NUM)
ONEXT U
ONEXT T
OKILL "PROCNAME" (* remove Show from the workspace.
OEND

PROCEDURE SHOW
OPARAM NUM:STRING
OSHELL "DISPLAY "+NUM
OEND

11-73
BASIC09 Reference

LAND Returns the logical AND of two numbers

Syntax: LAND(numl,n=2)

Function: Performs the logical AND function on a byte- or integer-type value. The operation involves a bit-by-bit logical AND of the two numbers you specify. For instance, if you LAND 5 and 6, the logic is like this:


Decimal 5 = Binary 0101
Decimal 6 = Binary 0110

0101
AND 0110

= 0100 = 4 Decimal

Parameters:

numl A byte- or integer-type number.

num2 A byte- or integer-type number.

Examples:

PRINT LAND(1 1 , 1 2 )

PRINT LAND($20,$FF)

Sample Program:

The following procedure asks eight questions and uses the eight bits of one byte (contained in the variable STORAGE) to indicate either a "yes" or "no" answer. If the answer is "yes," it sets a corresponding bit to 1. If the answer is "no," it sets a corresponding bit to 0, using LAND. This procedure operates in conjunction with the sample program for LXOR.


11-?4
              BASIC09 Command Reference l 11


PROCEDURE que5tion5
[]DIM QUESTION;STRINGI68J; T;INTEGER; X,STORAGE;HYTE
[]DIM ANSWER;STRINGI1)
OX-1
[]FOR T=1 TO 8
DREAD QUESTION
[]PRINT QUESTION; " (Y/N)? ";
OGET 1B,ANSWER
[]PRINT
pIF ANSWER="y" OR ANSWER="Y" THEN
[]STORAGE=LOR(STORAGE,X) (* OR STORAGE if yes.
[]ELSE
[]STORAGE-LAND(STORAGE,LNOT(X)) (* LAND STORAGE with NOT value if no.
[]END I F
pX=X#2
[]NEXT T
[]RUN 5ummary(STORAGE)
REND
[]DATA "Do you have more than one Color Computer"
[]DATA "Do you use your Color Computer for games"
[]DATA "Do you use your Color Computer for word processing"
[]DATA "Do you use your Color Computer for business applications"
[]DATA "Do you use your Color Computer at home"
[]DATA "Do you use your Color Computer at the office"
[]DATA "Do you use your Color Computer more than two hours a day"
[]DATA "Do you share your Color Computer with others"

11-75
BASIC09 Reference

        LEFT Returns characters from the left portion of a string


        Syntax: LEFT$(stringlength)


Function: Returns the specified number of characters from the specified string, beginning at the leftmost character. If length is the same as or greater than the number of characters in string, then LEFT$ returns all the characters in the string.

Parameters:

string A sequence of ASCII characters or a string
variable name.
length The number of characters you want to access.

Examples:

PRINT LEFT$("H0TD0G",3)

PRINT LEFT$(A$,6)

Sample Program:

The following procedure extracts the first name from a list of ten names with the LEFT$ function.

PROCEDURE firstname
ODIM NAMES:STRING; FIRSTNAME:STRINGI10J
pPRINT "Here are the first names:"
OFOR T--1 TO 10
pREAD NAMES
pPOINTER=SUHSTR(" ",NAMES) (* find space between first and last names.
pFIRSTNAME=LEFT=(NAMES,POINTER-1) (* extract first name,
OPRINT FIRSTNAME (# print first name.
ONEXT T
pEND
ODATA "Joe Blonski","Mike Marvel","Hal Skeemish","Fred Laungly"
pDATA "Jane Mistey","Wendy Paston","Martha Upshong","Jacqueline Rivers"
pDATA "Susy Reetmore","Wilson Creding"

11-?6