Skip to content

Basic09 Command Reference

Boisy Gene Pitre, PhD edited this page May 26, 2026 · 53 revisions

ABS: Return absolute value

Syntax: ABS(number)

Function: Computes the absolute value of number. A number's absolute value is its magnitude without regard to its sign. Absolute values are always positive or zero.

Parameters:

number: Any positive or negative number.

Examples:

PRINT ABS(.6561)
X=ABS(Y)

Sample Procedure: temperature

The following procedure asks you to type the temperature, and makes an appropriate comment. It uses ABS to get the absolute value of the temperature.

DIM TEMP:INTEGER
INPUT "What's the temperature outside? (Degrees F)...",TEMP
IF TEMP<0 THEN
PRINT "That's "; ABS(TEMP); " below zero !   Brrrrrrr"
END
ENDIF
IF TEMP=0 THEN
PRINT "Zero degrees? That's mighty cold!"
END
ENDIF
PRINT TEMP; " degrees above zero? That's kind of balmy..."
END

ACS: Return arccosine

Syntax: ACS(number)

Function: Calculates the arccosine of number. Use the DEG or RAD commands to tell Basic09 if number is in degrees or radians. If you do not specify degrees or radians, the default is radians.

Parameters:

number: The number for which you want to compute the arccosine.

Examples:

PRINT ASC(.6561)

Sample Procedure: arccosine

The procedure calculates the arccosine of a value you type and expresses the result in degrees.

DEG
DIM NUM:REAL
INPUT "Enter a number between -1 and 1",NUM
PRINT "The arccorsine of "; NUM; " is ---“; ACS(NUM)
END

ADDR: Return the location of a variable

Syntax: ADDR(name)

Function: Returns the absolute location in a process's address space of the variable, array, or data structure assigned to name. The address returned is that of the first character in the variable. If the variable is numeric, one or more of the locations might contain zero. For instance, if you use ADDR to obtain the address of an integer variable that contains the value 44, the first address location (byte) contains 0, and the second location contains 44.

Parameters:

name: The name of a string, a numeric variable, an array, or a data structure.

Examples:

This procedure displays the memory address where a variable named X resides:

Sample Procedure: address

This procedure uses ADDR to tell you the memory location of the variable that stores your keyboard entry.

DIM A:INTEGER
DIM TEST:STRING
INPUT "Type a String of characters...",TEST
A=ADDR(TEST)
PRINT "The String you typed it Stored at address”; A
PRINT "This is what it contains:..."
FOR T=A TO A+LEN(TEST)
PRINT CHR$(PEEK(T));
NEXT T
PRINT
END

AND: Performs a logical AND operation

Syntax: operand1 AND operand2

Function: Performs the logical AND operation on two or more values, returning a value of either TRUE or FALSE.

Parameters:

operand1, operand2: Can be either numeric or string values.

Examples:

PRINT A>3 AND B>3
PRINT A$="YES" AND H$="YES"

Sample Procedure: policy

The following program calculates an insurance premium rate that is based on the answers to some lifestyle questions. Every time you press E, the premium rate goes up. The procedure uses AND to increase the rate by two percent if you both smoke and drink.

DIM POLICY-VALUE,RATE:REAL
DIM SMOKE,DRINK:STRING[1]
POLICY_VALUE=1000000.
RATE=.001
INPUT "Do you smoke? (Y/N)...",SMOKE
INPUT "Do you drink? (Y/N)...",DRINK
IF SMOKE="Y" AND DRINK="Y" THEN RATE=RATE+.02
ELSE
IF SMOKE="Y" THEN RATE=RATE+.01
ENDIF
IF DRINK="Y" THEN RATE=RATE+.01
ENDIF
ENDIF
PRINT "Your premium is "; RATE* POLICY-VALUE
END

ASC: Returns ASCII code

Syntax: ASC (string)

Function: Returns the ASCII code for the first character of string. ASC returns the value as a decimal number. If string is null (contains no characters) Basic09 returns Error 67 (Illegal Argument).

Parameters:

string: Any string type variable or constant.

Examples:

PRINT ASC("Hello")
x = ASC(A$)

Sample Procedure: hexcheck

The following procedure determines whether the first character you enter is a hexadecimal digit. To do this, it gets the ASCII value of the character and compares it to the ranges for characters between 1 and 0 and A and F.

DIM A:INTEGER
DIM HEXNUM:STRING
LOOP
INPUT "Enter a hexadecimal value...“,HEXNUM
A=ASC(HEXNUM) \ 				(* GET THE ASCII CODE *)
EXITIF A<48 OR A>57 AND A<65 OR A>70 THEN
PRINT "Not a hex number."
END
ENDEXIT
PRINT "Ok."
ENDLOOP
END

ASN: Returns arcsine

Syntax: ASN(number)

Function: Calculates the arcsine of number. ASN expresses its result in radians unless you specify otherwise (see DEG).

Parameters:

number: The number for which you want to calculate the arcsine.

Examples:

PRINT ASC(.6561)

Sample Procedure: arcsine

The following program calculates the arcsine of a number you enter and expresses the result in degrees.

DIM NUM:REAL
DEG
INPUT "Enter a number (-1 to 1) ",NUM
PRINT "The arcsine of a "; NUM; " is ---"; ASN(NUM)
END

ATN: Returns arctangent

Syntax: ATN(number)

Function: Calculates the arctangent of number.

Parameters:

number: The number for which you want to find the arctangent.

Examples:

PRINT ASC(.6561)

Sample Procedure: anglecalc

This procedure calculates arcsine, arccosine, and arctangent for a value you enter.

DIM NUM:REAL
DEG
INPUT "Enter a number ",NUM
PRINT
PRINT " ","Arcsine","Arccosine","Arctangent"
PRINT "Number","Degrees","Degrees","Degrees"
PRINT “-------------------------------------------------------------“
IF NUM>1 OR NUM<-1 THEN
PRINT NUM,"UNDEF","UNDEF",ATN(NUM)
PRINT
END
ENDIF
PRINT NUM,ASN(NUM),ACS(NUM),ATN(NUM)
PRINT
END

BASE: Set array base

Syntax: BASE 0

BASE 1

Function: Sets a procedure's lowest array or data structure index to either 0 or 1. If you want to have the first elements in arrays set to 0, you must include B A S E 0 at the beginning of the procedure. The BASE statement does not affect string operations such as MID$, RIGHTS, and LEFTS. Basic09 always indexes the first character of a string as 1.

Parameters:

0 or 1: If you do not indicate a BASE setting in a procedure, Basic09 uses a default of 1.

Examples:

BASE 0

Sample Procedure: randomtest

This procedure determines how many times RND selects each number between 0 and 11 out of 1000 selections. It stores the results in an array of 12 elements. Because it specifies BASE 0, one of the elements in the array is 0. Whenever the procedure picks a random number, it increments the value in the corresponding array number by one.

BASE 0 						(* set the array base at 0.
DIM RND_ARRAY(12),X,R:INTEGER 	(* dimension array to hold results.
FOR X=0 TO 11
RND-ARRAY(X)=0 				(* initialize array elements at zero.
NEXT X
SHELL "TMODE PAU=0" 			(* turn off screen pause.
FOR X=1 TO 1000
R=RND(11) ( select random number 1000 times.
RND-ARRAY(R)=RND-ARRAY(R)+1		(* add 1 to appropriate element,
PRINT 1001-X 0 count down from 1000 to 1,
NEXT X
FOR X=0 TO 11 OPRINT "RND selected "; X; " "; RND-ARRAY(X); "times,
(*display array
NEXT X
SHELL "TMODE PAU=1" 0 turn scroll lock back on,
END

BYE: End procedure, terminate Basic09

Syntax: BYE

Function: Ends execution of a procedure and terminates Basic09. The statement closes any open files, but you lose any unsaved procedures or data.

Use BYE to exit packed programs that you call from OS-9 and especially programs that you call from procedure files. Parameters: None

Examples:

INPUT "Press ENTER to return to the system.";Z$
BYE

Sample Procedure: loan

This procedure calculates the payments and interest of a loan. When it is through, it exits the procedure and Basic09 with a BYE statement.

DIM PRIN,LENG.,RATE,MONPAY:REAL
DIM RESPONSE:STRING[1]
REPEAT
PRINT "Amortization Program"
DINPUT "How much do you want to borrow?...",PRIN
INPUT "For how many months?...",LENG
INPUT "At what interest rate?...",RATE
A=RATE/1200.
B=1-1/(1+A)^LENG
MONPAY=PRIN*A/H
MONPAY=INT(MONPAY*100+.5)/100
PRINT "Monthly payments are...$";
PRINT USING "R12.2<",MONPAY
PRINT "The total interest to pay is...$";
PRINT USING "r12.2<",MONPAY*LENG-PRIN
PRINT
INPUT "Do another calculation?...",RESPONSE
PRINT
PRINT
UNTIL RESPONSE<>"Y"
BYE
END

CHAIN: Execute another module

Syntax: CHAIN "module [parameters] [... ]"

Function: CHAIN performs an OS-9 chain operation, passing module as the name of a program to execute. If you include other parameters, CHAIN passes them to the executing module. The module must be programmed to expect parameters of the type you provide. CHAIN exits Basic09, unlinks Basic09, and returns the freed memory to OS-9. CHAIN can begin execution of any module, not only Basic09 modules. It executes the module indirectly through the shell in order to take advantage of the shell's parameter processing. This has the side effect of leaving the initiated shells active. Programs that repeatedly chain to each other eventually fill memory with waiting shells. To prevent this, use the EX option to initialize a shell. Basic09 does not close files that are open when you execute CHAIN. However, the OS-9 FORK call passes only the standard I/O paths (0, 1, and 2) to a child process. Therefore, if you need to pass an open path to another program segment, use the EX shell option.

Parameters:

module: The name of the procedure module you want Basic09 to execute. parameters: String data passed to the chained module.

Examples:

CHAIN "ex Basic09 menu"
CHAIN "basic09 #10k sort (""datafile"", ""tempfile"")"
CHAIN "dir /d0"
CHAIN "dir; echo *** Copying Directory ***; ex basic09 copydir"

Sample Procedure: chaining

This procedure chains to two others to display a directory or a file. It uses CHAIN to call the procedures.

DIM RESPONSE:BYTE
PRINT USING "S26","- MENU -" 		(* print menu title.
PRINT
PRINT "1. List current data directory" (* print menu.
PRINT "2. Display a file"
PRINT "3. Exit to system"
PRINT
INPUT "Select a function (1-3) ",RESPONSE (* function you want.
ON RESPONSE GOTO 100,200,300   (* select appropriate function.
100 CHAIN "EX Basic09 dirlook" (* chain to list directory.
200 CHAIN "EX Basic09 display" (* chain to list file.
300 BYE

Procedure: dirlook

REM Lists the specified directory
SHELL "dir"                 (* execute dir command.
CHAIN "ex basic09 chaining" (* chain back to calling proc.
END

Procedure: display

REM Lists the specified file.
DIM FILE,JOB:STRING
INPUT "Path of file to display...",FILE
JOB="LIST "+FILE
SHELL JOB                     (* list specified file.
CHAIN "ex basic09 chaining"   (* chain back to calling process
END

CHD: Change data directory

CHX: Change execution directory

Syntax: CHD dirpath

CHX dirpath

Function: Changes the current data or execution directory.

Parameters:

dirpath: An existing data or execution directory.

Examples:

CHD "/D1/ACCOUNTS/RECEIVABLE"
CHX "/D1/CMDS"
CHD ".."

Sample Procedure: chdtest

This procedure creates a directory, and makes it the data directory. Then, it creates a file in the new directory, exits the new directory, and deletes the file and the directory.

DIM PATH:BYTE
SHELL "MAKDIR TEST"             (* create new directory named TEST.
CHD "TEST"                      (* make TEST the data directory.
CREATE #PATH,"samplefile":WRITE (* create a file in TEST.
REM Write data into the new file
WRITE #PATH,"This file is for testing only."
WRITE #PATH,"It will be destroyed when this procedure ends."
CLOSE #PATH
SHELL "LIST samplefile"         (* list the new file.
CHD ".."                        (* make the ROOT the data directory.
SHELL "DEL TEST/samplefile" .   (* delete the file.
SHELL "DELDIR TEST"             (* delete the directory.
END

CHR$: Return ASCII character

Syntax: CHR$(code)

Function: Returns the ASCII character for the value of code. CHR$ is the inverse of the ASC function, which returns the ASCII code for a given character.

Parameters:

code: The ASCII value for a keyboard character or special block graphics character.

Examples:

PRINT CHR$(88)

Sample Procedure: secret

By increasing by one the ASCII values of characters you type, the following program creates a secret code. It uses CHR$ to display the secret code.
DIM TEXT,SECRETLINE:STRING[80]
DIM T,CODECHAR:INTEGER
TEXT=""
SECRETLINE=""
PRINT "Type a line to code in capital letters..."
INPUT TEXT                                   (* you type a line,
FOR T=1 TO LEN(TEXT)
CODECHAR=ASC(MIDS(TEXT,T,1))                 (* look at each character in line.
IF CODECHAR=90 THEN                          (* is it "Z"? If yes then
CODECHAR=64                                  (* make it one less than "A".
ENDIF
IF CODECHAR=32 THEN                          (* is character a space? If yes then
CODECHAR=31                                  (* decrease its value by one.
ENDIF
SECRETLINE=SECRETLINE+CHRS(CODECHAR+1)       (* add 1 to characters.
NEXT T
PRINT SECRETLINE                             (* print the secret code.
END

CHX: Change execution directory

CHD: Change data directory

Syntax: CHX dirpath

CHD dirpath

Function: Changes the current execution or data directory.

Parameters:

dirpath: An existing execution or data directory.

Examples:

CHX "/D1/CMDS"
CHD "/D1/ACCOUNTS/RECEIVABLE"
CHD “..”

CLOSE: Deallocate file or device path

Syntax: CLOSE #pathnum

Function: Deallocates the file or device path specified by pathnum. When you OPEN or CREATE a file, Basic09 allocates a path number to the variable you supply in the OPEN or CREATE command. The system then knows the path by that number. If the path you CLOSE is to a non-shareable device (such as a printer), the system releases the device for other use. Do not close paths 0, 1, and 2 (the standard I/O paths) unless you immediately open a new path to take over the standard path number.

Parameters:

pathnum: The name of variable containing the path number or the actual number of the path to a file or device.

Examples:

CLOSE #FILEPATH, #PRINTERPATH, #TERMPATH
CLOSE #5, x6, #7
CLOSE #1 \ 					(* closes the standard output path *)
OPEN #PATH,"/T1"    \ 			(* redirects standard output *)

Sample Procedure: close

This procedure creates a directory named TEST and changes it to the data directory. It then creates a file named Samplefile and writes data to the file. Finally it changes back to the parent directory and deletes Samplefile and TEST.

DIM PATH;BYTE
SHELL "MAKDIR TEST"
CHD "TEST"
CREATE #PATH,"samplefile";WRITE 			(* create a new file.
WRITE #PATH,"This file is for testing only."
WRITE #PATH,"It will be destroyed when this procedure ends."
CLOSE #PATH 								(* close the file.
SHELL "LIST samplefile"
CHD ".."
SHELL "DELDIR TEST"
END

COS: Return cosine

Syntax: COS(number)

Function: Calculates the cosine of number. Unless you specify DEG, COS interprets the value of number in radians.

Parameters:

number: The number for which you want to find the cosine.

Examples:

PRINT COS(45)

Sample Procedure: ratiocalc

This procedure calculates sine, cosine, and tangent of a value you enter.

DIM NUM:REAL
DEG
INPUT "Enter a number...",NUM
PRINT "Number", "SINE","COSINE","TAN"
PRINT
PRINT ANGLE,SIN(NUM),COS(NUM),TAN(NUM)
END

CREATE: Establish a disk file.

Syntax: CREATE #path, "pathlist" [access mode] [ + access mode] [ +... ]

Function: Creates a file on a disk. When you create a file, you can select one or more of the following access modes for the file:

Mode: Function

READ: Lets you read (receive) data from a file but does not let you write (send) data to the file.

WRITE: Lets you write data to a file but does not let you read data from a file.

UPDATE: Lets you both read from and write to a file.

Parameters:

path: The name of the variable in which Basic09 stores the number of the opened path.

pathlist: The route to the file or device to be opened, including the filename, if appropriate.

access: mode The type of access to be allowed for the file or device. Use plus symbols to allow more than one type of access with a single file.

Notes: You can access files either sequentially or randomly. With random access, you must establish the filing system you want for a particular application. Files are byte-addressed, and you are not restricted by explicit record lengths. You can read the data one byte at a time, or in whatever size portions you want. A new file has a size of zero. OS-9 then expands the file automatically when PRINT, WRITE, or PUT statements write beyond the current end-of-file.

Examples:

CREATE #TRANS,"transportation":UPDATE
CREATE #SPOOL,"/user4/report":WRITE
CREATE #OUTPATH,name$:UPDATE+EXEC

Sample Procedure: close

This procedure CREATES a directory named TEST and makes it the data directory. It creates a file in TEST named Samplefile, writes data to the file, then resets the parent directory as the data directory. Finally, it deletes Samplefile and TEST.

DIM PATH:BYTE
SHELL "MAKDIR TEST"
CHD "TEST"
CREATE #PATH,"samplefile":WRITE (* create a file.
WRITE #PATH,"This file is for testing purposes only."
WRITE #PATH,"It will be destroyed when this procedure ends."
CLOSE #PATH (* close the file.
SHELL "LIST samplefile"
CHD ".."
SHELL "DELDIR TEST"
END

DATA: Store numeric and string information

Syntax: DATA "item" [,"item",... ]

Function: Stores numeric and string constants to be accessed by a READ statement. A DATA line can contain up to 254 characters. Each item in the list must be separated by commas.

You can place DATA statements anywhere in a procedure that is convenient. Basic09 reads sequentially, starting with the first item in the first DATA statement, and ending with the last item in the last DATA statement. The following rules apply to data items: You must place all string data between quotation marks. To include quotes.n string-type data, use consecutive quotation marks, like this: DATA " H e 5 a i d, " " g o home"" to me". You can use RESTORE to reset the data pointer. Using RESTORE without an argument resets the pointer to the beginning of the data items. Using RESTORE with a line number, resets the pointer to the first item in the specified line. The READ statement can support a list of one or more variable names of various types. The data types in DATA statements must match the variable types used in the corresponding READ statements. You can include arithmetic expressions in data items. READ causes the expressions to be evaluated and returns the result of the expression as the data item.

Parameters:

item: Numeric or string characters. Enclose string characters in quotation marks.

Examples:

DATA 1.1,1.5,9999,"CAT","DOG"
DATA SIN(TEMP/25), COS(TEMP*PI)
DATA TRUE,FALSE,TRUE,TRUE,FALSE
DATA "The rain in Spain","falls mainly on the plain"

Sample Procedure: weekday

This procedure calculates the day of the week for a date you enter. A data statement contains the names of the weekdays.

DIM X,DAY,MONTH,YEAR,CALC:INTEGER
DIM ANUM,HNUM,CNUM,DNUM,ENUM,FNUM,GNUM,HNUM,INUM: INTEGER
DIM WEEKDAY(7):STRING[9]
PRINT USING "S60^","Day of the Week Program"
PRINT USING "S60^","For any year after 1752"
PRINT
INPUT "Enter day of the month as two digits, such as 08...",DAY
INPUT "Enter month as two digits, such as 12...",MONTH
INPUT "Enter year as four digits, such as 1986...",YEAR
FOR X=1 TO 7
READ WEEKDAY(X)
NEXT X
ANUM=INT(.6+1/MONTH)
BNUM=YEAR-ANUM
CNUM=MONTH+12 * ANUM
DNUM=BNUM/100
ENUM=INT(DNUM/4)
FNUM=INT(DNUM)
GNUM=INT(5*BNUM/4)
HNUM= INT(13*(CNUM+1)/5)
INUM=HNUM+GNUM-FNUM+ENUM+DAY-1
INUM=INUM-7*INT(INUM/7)+1
PRINT
PRINT "The day of the week on "; DAY; "/"; MONTH;
PRINT "/"; YEAR; " is..."; WEEKDAYCINUM)
DATA "Sunday","Monday","Tuesday","Wednesday", "Thursday"
DATA "Friday","Saturday"
END

DATE$: Provide date and time

Syntax: DATE$

Function: Returns the date and time. The OS-9 internal date is kept in the format: year/month/day hour:minutes:seconds If your OS-9 Startup file contains the SETIME command, the system asks you to enter the date and time whenever it boots. If it does not contain the SETIME command, the date and time start from 86/09/01:00:00:00. You can use the normal string functions to access the data contained in DATE$, but you cannot use functions or operations that attempt to change or append to its values. To reset the date or time or both, use the SHELL command, such as:

SHELL "SETIME"

Parameters: None

Examples:

PRINT DATE$

Sample Procedure: date

This program is essentially the same as the sample program for the DATA statement, except that it gets the day, month, and year from DATE$.

DIM X,DAY,MONTH,YEAR,CALC:INTEGER
DIM ANUM,HNUM,CNUM,DNUM,ENUM,FNUM,GNUM,HNUM,INUM:INTEGER
DIM WEEKDAY(7):STRING[9]
MONTH=VAL(MID$(DATE$,4,2)) (* get month from DATE$.
DAY=VAL(MID$(DATE$,7,2)) (* get day from DATE$.
YEAR=VAL("19"$(LEFT$(DATE$,2)) (* get year from DATE$.
FOR X=1 TO 7
READ WEEKDAY(X)
NEXT X
ANUM=INT(.6+1/MONTH)
BNUM=YEAR-ANUM
CNUM=MONTH+12*ANUM
DNUM=BNUM/100
ENUM=INT(DNUM/4)
FNUM=INT(DNUM)
GNUM=INT(5*BNUM/4)
HNUM=INT(13*(CNUM+1)/5)
INUM=HNUM+GNUM-FNUM+ENUM+DAY-1
INUM=INUM-7*INT(INUM/7)+1
PRINT
PRINT "Today is "; WEEKDAY(INUM)
DATA "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
DATA "Saturday"
END

DEG: Return trigonometric calculations in degrees

Syntax: DEG

Function: Causes a procedure to calculate trigonometric values in degrees. If you do not include the DEG statement, procedures produce radian values.

Parameters:

None

Examples:

DEG

Sample Procedure: degcalc

This procedure calculates the sine, cosine, and tangent for a value you enter. Because it uses the DEG statement, it displays the results in degrees.

DIM NUM:REAL
DEG
INPUT "Enter a number...”,NUM
PRINT
PRINT "Number", "SINE","COSINE","TAN"
PRINT “----------------------------------------------------------------“
PRINT NUM,SIN(NUM),COS(NUM),TAN(NUM)
PRINT
END

DELETE: Erase a disk file

Syntax: DELETE "pathname"

Function: DELETE removes a file from disk storage and releases the portion of the disk on which it resides. When you DELETE a file, it is permanently lost.

Parameters:

pathname: The complete pathlist to the file you want to delete, including the drive and one or more directories, if appropriate. You must surround the pathlist with quotation marks.

Examples:

DELETE "myfile"
DELETE "/D1/ACCOUNTS/receivable5"

Sample Procedure: close

This procedure creates a file named Samplefile, writes data to the file, then closes it. It then lists the file before deleting it.

DIM PATH:BYTE
CREATE #PATH,"Samplefile":WRITE (* create a file.
WRITE #PATH,"This file is for testing purposes only."
WRITE #PATH,"It will be destroyed when this procedure ends."
CLOSE #PATH (* close the file.
SHELL "LIST Samplefile"
DELETE "Samplefile"
END

DIM: Assign variable storage

Syntax: DIM variable[,...] [:type][;variable][,...][: type)[...]

Function: Assigns storage space and declares types for variables, arrays, or complex data structures.

Parameters:

variable: A simple variable, an array structure, or a complex data structure.

type: BYTE, INTEGER, REAL, BOOLEAN, STRING, or user defined.

Notes: You declare simple arrays with DIM by using the variable name, without a subscript. If you do not explicitly declare variables, the system makes them type real unless they are followed by a dollar sign ($). The system dimensions variables ending with a dollar sign ($) as strings, with a length of 32 bytes. You must declare types of all other simple variables as to type.

You can declare several variables of the same type by separating them with commas. To separate variables of different types, follow each type group with a colon, the type name, and then a semicolon.

Define a maximum length for a string variable by enclosing the length in brackets following the type, like this: DIM name:5tring[25]

If you do not define a maximum length, Basic09 uses a default length of 32 characters. You can declare a shorter length or a longer length, up to the capacity of Basic09's memory. If you try to extend a string beyond its declared length, or beyond the default length, the system ignores all extra characters. Thus the following:

DIM name:string[10]

name = "Abbernathinsky"

produces the string:

Abbernathi

Arrays can have one, two, or three dimensions. The DIM format for dimensioned arrays is the same as for simple variables, except that you must follow each array name with a subscript, enclosed in parentheses, to indicate its size. The maximum array size is 32767.

Arrays can be either of the standard Basic09 type or of a user-defined type. For information on creating your own types for simple variables, arrays, and complex data structures, see TYPE.

Examples:

DIM logica1:H00LEAN
DIM a,b,c:INTEGER
DIM name,address,zip:STRING
DIM name:STRING[25]; address:STRING[30]; zip: INTEGER
DIM no1,no2,no3:REAL;no4,noS,no6:INTEGER; no7:BYTE

Sample Procedure: alien

This procedure randomly selects letters and vowels to create six-letter words that might look like alien names. It first DIMs nine string variables to contain the letters selected for each name. It DIMs two integer variables to provide a loop counter and to store the number of names you request.

When asked, type the number of names you want to have the procedure generate.

DIM B,BEGIN,F,FINISH:STRING
DIM VOWELS,VOWEL1,VOWEL2:STRING
DIM MID1,MID2:STRING
DIM T,RESPONSE:INTEGER
VOWELS="aeiouy"
INPUT "How many alien names do you want to See?...",RESPONSE
BEGIN="AHCDFGHJKLMNPRSTVWXZ"
FINISH="ehlmnprstvwyz"
FOR T=1 TO RESPONSE
B=MID$(BEGIN,RND(19)+1,1)
F=MID$(FINISH,RND(12)+1,1)
MID1=CHR$(RND(25)+97)
MID2=CHR$(RND(25)+97)
VOWEL1=MID$(VOWELS,RND(5)+1,1)
VOWEL2=MID$(VOWELS,RND(5)+1,1)
PRINT B; VOWEL1; MID1; MID2; VOWEL2; F,
NEXT T
PRINT
END

DO: Execute procedure lines in a loop

Syntax: WHILE expression DO proclines ENDWHILE Function: Establishes a loop that executes the procedure lines between DO and ENDWHILE as long as the result of the expression following WHILE is true. Because the loop is tested at the top, the lines within the loop are never executed unless expression is true.

Parameters:

expression: A Boolean expression (produces a result of True or False).

proclines: Program lines to execute if the expression is true.

See WHILE/DO/ENDWHILE for more information.

ELSE: Execute alternate action

Syntax: IF condition THEN action

secondary action

Function: ELSE provides access to a secondary action within an IF/THEN test. When the condition tested by IF is not true, Basic09 executes the secondary action preceded by ELSE.

ELSE
ENDIF

Parameters:

Condition: A Boolean expression (produces a result of True or False). Action A line number to which the procedure is to transfer execution, or a program statement. If action is a line number, do not include the ENDIF statement in the IF test.

secondary: action One or more program statements. For more information, see IF/THEN/ELSE

END: Terminate a procedure

Syntax: END ["text"]

Function: Ends procedure execution and returns to the calling procedure, or to the highest level procedure. If you provide output text for END, it functions in the same manner as PRINT. You can use END several times in the same procedure. END is not required as the last statement in a procedure.

Parameters:

text: A literal string or a string-type variable.

Examples:

END "Program Terminated"

LAST="Session over"

END LAST

Sample Procedure: loaner

This procedure calculates a loan's term, using END to terminate routines.

DIM YOUPAY,PRINCIPLE,INTEREST,NUMPAY,YEARS,MONTHS:REAL
DIM RESPONSE:STRING[1]
REPEAT
PRINT
PRINT USING "S45^","Loan Terms"
PRINT -
INPUT " Amount of Regular Payments ",YOUPAY
INPUT " Enter the Principle ",PRINCIPLE
INPUT " Enter the Annual Interest Rate ",INTEREST
INPUT " Enter the Number of Payments Yearly",NUMPAY
YEARS=-(LOG(1-PRINCIPLE*(INTEREST/100)/(NUMPAY*YOUPAY))/
(LOG(1+INTEREST/100/NUMPAY)* NUMPAY))
MONTH=INT(YEARS*12+.5)
YEARS= INT(MONTH/12)
MONTH=MONTH-YEARS*12
PRINT " The Term of Your Loan is "; YEARS; " years and "; MONTH; " months."
INPUT "Calculate another or Quit (C/Q)?...", RESPONSE
UNTIL RESPONSE<>"C" AND RESPONSE<),"c"
END "Goodbye-I hope I helped you."

ENDEXIT: Leave loop if a condition is True

Syntax: EXITIF condition THEN Proclines ENDEXIT Function: ENDEXIT terminates an EXITIF test. You always use EXITIF/THEN/ENDEXIT inside a procedure loop. If the Boolean expression tested by EXITIF is true, Basic09 executes the program statements between THEN and ENDEXIT and then transfers program operation outside the loop. If the condition tested by EXITIF is not true, loop execution continues at the statement following ENDEXIT.

Parameters:

condition: A comparison operation that returns either True or False, such as A = B, A<B, or A=B=C. proclines: One or more statements to perform if the Boolean expression tested by EXITIF is True.

For more information, see EXITIF/THEN/ENDEXIT

ENDIF: Close IF statement

Syntax: IF condition THEN action [ELSE secondary action]

Function: ENDIF terminates an IF/THEN condition test. If the condition tested by IF is true, Basic09 executes the statements between THEN and ENDIF. If the condition tested by IF is not true, Basic09 transfers execution to the procedure line following ENDIF or (optionally) executes the statements following ELSE.

ENDIF

Parameters:

condition: A Boolean expression (produces a result of True or False). action: A line number to which the procedure is totransfer execution. Action can also be a program statement. If action is a line number, do not include the ENDIF statement in the IF test. secondary: A program statement. action: For more information, see IF/THEN/ELSE/ENDIF.

ENDLOOP: Close LOOP statement

Syntax: LOOP statement(s)

Function: ENDLOOP terminates a procedure loop established by the LOOP command. Basic09 endlessly executes all procedure statements between LOOP and ENDLOOP repeatedly unless a condition test within the loop (such as EXITIF/ THEN/ENDEXIT, or IF/THEN) transfers execution outside of the loop.

ENDLOOP

Parameters:

staternent(s): One or more procedure lines that execute within the loop. For more information, see LOOP/ENDLOOP

ENDWHILE: Close WHILE statement

Syntax: WHILE condition DO proclines ENDWHILE

Function: Forms the bottom of a WHILE loop. WHILE causes the procedure lines between DO and ENDWHILE to execute as long as the result of the expression following WHILE is true. Because the loop is tested at the top, the lines within the loop are never executed unless the expression is true.

Parameters:

condition: A Boolean expression (produces results of True or False). proclines: Are program lines to execute if the expression is true. For more information, see WHILE/DO/ENDWHILE.

EOF: Test for end-of-file

Syntax: EOF (path)

Function: Tests for the end of a disk file. The function returns a value of True when it encounters an end-of-file; otherwise, it returns False. Use EOF with a READ or GET statement.

Parameters:

path: The number of the path you are accessing. BASIC 09 automatically stores a path number into the variable you specify during a CREATE or OPEN operation.

Examples:

IF EOF(xPATH) THEN
CLOSE #PATH
ENDIF

Sample Procedure: readfile

This procedure redirects a listing of the current directory into a file named Dirfile. It then lists Dirfile to the screen. EOF tells the WHILE/ENDWHILE loop when the READ operation reaches the end of the file.

DIM A:STRING[80]
DIM PATH:BYTE
SHELL "DIR > dirfile"
OPEN #PATH,"dirfile":READ
WHILE NOT EOF(#PATH) DO
READ *PATH,A
PRINT A
ENDWHILE
CLOSE #PATH
END

ERR: Return error code

Syntax: ERR

Function: Returns the error code of the most recent error. Basic09 automatically sets the ERR code to zero after you reference it. ERR is only useful when used in conjunction with Basic09's ON ERROR error trapping functions. See Appendix A for a list of all Basic09 error codes. Parameters: None

Examples:

ERRNUM = ERR
IF ERRNUM = 218 THEN
PRINT "File already exists. Please use another filename."
ENDIF

Sample Procedure: readfile

This procedure displays the contents of a file you select. If the file doesn't exist (Error 216, Pathname not found), the procedure uses ERR to tell you. If an error other than Error 216 occurs, the procedure displays I can't handle error x x, where xx is the code of the error.

DIM READFILE:STRING; A:STRING[80]; PATH:BYTE
10  INPUT "Type the pathli5t of the file to read...",READFILE
ON ERROR GOTO 100 	(* if an error occurs, skip to line 100.
OPEN #PATH,READFILE:READ
WHILE EOF(#PATH)<>TRUE DO
READ #PATH,A
PRINT A
ENDWHILE
CLOSE #PATH
END
100  ERRNUM=ERR 		(* store the error code in ERRNUM.
IF ERRNUM=216 THEN 	(* if file doesn't exist say 5o.
PRINT "I can't find the file...Please try again."
ON ERROR
GOTO 10
ENDIF
PRINT "Sorry, I can't handle error number "; ERRNUM ( other error.
CLOSE #PATH
END

ERROR: Simulate an error

Syntax: ERROR code

Function: Simulates the error specified by code. You would mainly use this command to test ON ERROR GOTO routines. When Basic09 encounters an ERROR statement, it proceeds as if the error corresponding to the specified code has occurred. Refer to Appendix A for a listing of error codes and their meanings.

Parameters:

code: The code of the error you want to simulate.

Examples:

ERROR 207
ERRNUM = ERR
IF ERRNUM = 207 THEN
PRINT "Memory is full. The current data is being saved to disk."
ENDIF

Sample Procedure: errortest

This program creates a file named Testl. Before creating the file, it checks to see if it already exists. If the file exists, the procedure deletes it. An error trap catches any error that might occur. To test if the trap works for Error 216, "Pathname not found", the statement ERROR 216 is inserted as the fourth line. After testing the ~ trap to make sure it works, delete this line to use the procedure

DIM PATH,ERRNUM:HYTE; RESPONSE:STRING[1]
BASE 0
ON ERROR GOTO 10 			(* set error trap
ERROR 216 				(* simulate error
DELETE "teSt1"
GOTO 100
10  ERRNUM=ERR
IF ERRNUM=216 THEN
INPUT "File doesn't exist...continue? (Y/N)",RESPONSE
IF RESPONSE="N" THEN
END "Procedure terminated at your request…”
ENDIF
ENDIF
ON ERROR 				(* turn off error trap
100  CREATE #PATH, "test 1 ":WRITE
END
EXITIF/THEN/ENDEXIT
Exit from loop if a condition is true
**Syntax:** EXITIF condition THEN
statement
ENDEXIT
**Function:** Use these statements with loop constructions (particularly LOOP and ENDLOOP) to provide an exit for what is otherwise an endless loop. EXITIF performs a test of a Boolean expression, such as A<B. The THEN statement precedes any operation you want to execute if the expression is true. You must always follow EXITIF with an ENDEXIT.
If the Boolean expression following an EXITIF is false, execution of the program transfers to the statement immediately following the body of the loop (after the ENDEXIT statement). Otherwise, Basic09 executes the statements) between EXITIF and ENDEXIT, then transfers control to the statement following the body of the loop.
You can also use EXITIF and ENDEXIT with types of loop constructions other than LOOP/ENDLOOP.

Parameters:

Boolean: A comparison operation that returns either expression True or False, such as A=B, A<B, or A=B=C. statement: An operation to be performed if the Boolean expression tested by EXITIF is True, such as:

PRINT A is less than H.

Examples:

LOOP
COUNT=COUNT+1
EXITIF COUNT>100 THEN
DONE = TRUE

ENDEXIT

PRINT COUNT
X = COUNT/2
ENDLOOP

Sample Procedure: onearm

This procedure simulates a gambling machine by randomly selecting among several fruit names and displaying them: It gives you a starting stake of $25 and, depending on the combination of fruit selected, it adds or subtracts from your stake.

If your stake drops to zero, an EXITIF statement ends the procedure and tells you that you're broke.

DIM FRUIT1,FRUIT2,FRUIT3,STAKE:INTEGER; FRUIT(8): STRING[6]
STAKE=25
PRINT \ PRINT "You have $"; STAKE; " to play with."
FOR T=1 TO 8
READ FRUIT(T)
NEXT T
L00P
FRUIT1=RND(7)+1 \FRUIT2=RND(7)+1 \FRUIT3=RND(7)+1
PRINT FRUIT(FRUIT1); " "; FRUIT(FRUIT2); " "; FRUIT(FRUIT3)
IF FRUIT(FRUIT1)=FRUIT(FRUIT2) AND FRUIT(FRUIT1)= FRUITCFRUIT3) THEN STAKE=STAKE+10
ELSE
IF FRUIT(FRUIT1)=FRUIT(FRUIT2) OR FRUIT(FRUIT1)= FRUIT(FRUIT3) OR   FRUIT(FRUIT2)=FRUIT(FRUIT3) THEN
STAKE=STAKE+ 1
ELSE
STAKE=STAKE-1
ENDIF
ENDIF
REM exit play loop is Stake is less than $1.
EXITIF STAKE<1 THEN
PRINT
PRINT "You're Busted...Better go home."
ENDEXIT
PRINT "Your stake is now $"; STAKE; "."
PRINT
PRINT
INPUT "Press ENTER to pull again...",Z$
ENDLOOP
END
DATA "ORANGE","APPLE","CHERRY","LEMON","BANANA"
DATA "PEAR", "PLUM","PEACH"

EXP: Return natural exponent

Syntax: E XP(n um ber)

Function: Returns the natural exponent of number, that is, e (2.71828183) to the power of number. Number must be positive. This function is the inverse of the LOG function. Therefore, number = EXP(LOG(number)).

Parameters:

number: A positive value.

Examples:

PRINT EXP(2)

Sample Procedure: exprint

This procedure calculates the exponent of values in the range 0-1.

FOR T=0 TO 1 STEP.03
PRINT EXP(T),EXP(T+.01),EXP(T+.02)
NEXT T
END

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 Procedure: quiz

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

DIM REPLY,VALUE:BOOLEAN; ANSWER:STRING[1]; QUESTION:STRING[80]
FOR T-1 TO 5
READ QUESTION,VALUE
PRINT QUESTION
PRINT "(T) = TRUE              (F) = FALSE"
PRINT "Select T or F:    ";
GET x1,ANSWER
IF ANSWER="T" THEN
REPLY=TRUE
ELSE
REPLY=FALSE
ENDIF
IF REPLY=VALUE THEN
PRINT \ PRINT "That's Correct...Good Show!"
ELSE
PRINT "Sorry, you're wrong...Better Luck next time."
ENDIF
PRINT \ PRINT \ PRINT
NEXT T
DATA "In computer talk, CPU stands for Central Packaging Unit.", FALSE   DATA "The actual value of 64K is 6SS36 bytes.",TRUE ODATA "The bits in a byte are normally numbered 0 through 7?",TRUE
DATA "Basic09 has four data types.",FALSE
DATA "The LAND function is a Boolean type operator.",FALSE
END

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 Procedure: printfix

This procedure displays the FIXed values of seven constants.

PRINT FIX(1.2)
PRINT FIX(1.3)
PRINT FIX(1.5)
PRINT FIX(1.8)
PRINT FIX(99.566666)
PRINT FIX(50.1 )
PRINT FIX (.7654321 )
PRINT FIX(-12.44)
PRINT FIX(-9.99)
ND

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 Procedure: convert

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

DIM T: INTEGER; MEASURE:STRING[11]
FOR T=1 TO 1 0
IF T=1 THEN
MEASURE="centimeter "
ELSE
MEASURE="centimeters"
ENDIF
PRINT T; " "; MEASURE; “ is “; FLOAT(T)*.3937; " inches."
NEXT T
END
FOR/NEXT/STEP Establish a loop

Syntax:

[procedure statements]

FOR variable = init val TO end val [STEP value]
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 within the loop. statements

Notes: If you provide an initial value that is greater than the final value, Basic09 skips the program loop entirely unless you specify a negative STEP value. Specifying a negative value for STEP causes the loop to decrement from the initial value to the end value. 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. 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 Procedure: multable

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

PRINT USING "S45^",”MULTIPLICATION TABLE"
PRINT
DIM I,J:INTEGER
FOR I=1 TO 9
FOR J=1 TO 9
IF J>1 THEN
PRINT I*J; TAB(5*J);
ELSE PRINT I*J; "|";
ENDIF
NEXT J
IF I=1 THEN
PRINT ""
PRINT “-------------------------------------------------------“
ENDIF
PRINT
NEXT I
END

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. For 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/Opaths (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 Procedure: filenames

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

DIM DIRECTORY,FILENAME:STRING; CHARACTER:STRING[1]; FILES(125):STRING[15]; PATH,COUNT,T:INTEGER
COUNT=0
FILENAME=""
FOR T=1 TO 125 				(* initialize array elements to null.
FILES(T)=""
NEXT T
INPUT "Pathlist of directory to read...",DIRECTORY (* dir to copy.
ON ERROR GOTO 10
DELETE "dirfile" 			(* if dirfile already exists, delete it.
10  ON ERROR
SHELL "DIR "+DIRECTORY+” > dirfile" (* copy directory into file.
OPEN #PATH,"dirfile":READ 			(* open the file for reading.   REPEAT
REM Get characters from the file until the first carriage return - the beginning of the first filename.
GET xPATH,CHARACTER 				(* get characters from the file.
UNTII CHARACTER=CHRS(13)
REM
20  LOOP
EXITIF EOF(#PATH) THEN
GOTO 200 						(* quit when end of file.
ENDEXIT
REM get a character from the file until it finds a. non-valid filename character.
GET #PATH,CHARACTER
REM
EXITIF CHARACTER<=" " OR CHARACTER>"z" THEN
GOTO 100
ENDEXIT
FILENAME=FILENAME+CHARACTER 		(* build the filename.
ENDL00P
100  WHILE NOT(EOF(#PATH)) DO
GET #PATH,CHARACTER 		(* check for non-valid filename characters.
EXITIF CHARACTER>" " AND CHARACTERS<="z" THEN (* check if valid char,   COUNT=COUNT+1
FILES(COUNT)=FILENAME 				(* store filename in array.
PRINT FILENAME, 					(* display the extracted filename.
FILENAME="" 						(* set variable to NULL.
FILENAME=FILENAME+CHARACTER 	(* last character begins new filename.
GOTO 28 						(* go get the rest of filename.
ENDEXIT
ENDWHILE
200  CLOSE #PATH
DELETE "dirfile" 			(* names are all in array so delete file.
CREATE OPATH,"dirfile":WRITE 		(* create the file again.
FOR T-1 TO COUNT
WRITE #PATH,FILES(T) 		(* fill the file with individual filenames.
NEXT T
CLOSE #PATH
PRINT
PRINT "              *The directory has "; COUNT; "entries."
PRINT  "                They are now stored in a file named Dirfile."
end

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 execution is to continue.

Examples:

GOSUB 1 0 0

Sample Procedure: calc

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.

DIM NUM1,NUM2:REAL; OP:STRING[1]; A:INTEGER
1  INPUT "NUMBER 1 ";NUM1
IF NUM1 <0 THEN
END
ENFIF
INPUT "NUMBER 2 ";NUM2
INPUT "OPERATOR ";OP
A=SUBSTR(OP,"+-*/^")
0N A GOSUB 10,20,30,40,50
GOTO 1
10  PRINT NUM1 +NUM2 \ RETURN
20  PRINT NUM1 -NUM2 \ RETURN
30  PRINT NUM1 *NUM2 \ RETURN
40  PRINT NUM1 /NUM2 \ RETURN
50  PRINT NUM1  NUM2 \ RETURN
END
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: One or more procedure statements to be executed if condition is true.

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

Examples:

IF AFB THEN 100
IF A<B THEN 100
ELSE
A=A-1
ENDIF
IF TEST=TRUE THEN
PRINT "The test is a success..."
ENDIF
I F A < B THEN
PRINT "A is 1es than B"
ELSE
PRINT "B is 1ess than A"
ENDIF

Sample Procedure: purge

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.

DIM PATH: INTEGER
DIM NAMEC100):STRING
DIM WILDCARD:STRING
X=0
OPEN #PATH,"dirfile":READ
WHILE NOT(EOF(#PATH)) DO
X=X+1
READ #PATH,NAME(X)
ENDWHILE
FOR T=1 TO X
[‘]PRINT NAME(T),
NEXT T
INPUT "Wildcard Character5...",WILDCARD
FOR T=1 TO X
ON ERROR GOTO 100
IF SUHSTR(WILDCARD,NAME(T))>0 OR WILDCARD ="*" THEN
PRINT "DELETING "; NAME(T); “......”
DELETE NAME(T)
ENDIF
10  NEXT T
END
100  PRINT "* * * ERROR * * * "; NAME(T) " cannot be deleted..continuing."   GOTO 10

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:STRING[1]
CHAR=""
WHILE CHAR="" DO
RUN INKEY(CHAR)

ENDWHILE

PRINT ASC(CHAR)

Sample Procedure: Calculate

DIM CHAR : STRING[1]
DIM LOOKUP:STRING[7]
DIM FIRST,SECOND:REAL
DIM FLAG:INTEGER
LOOKUP="+-*/^<>"
1 FLAG=0 \CHAR=""
PRINT "Enter the first number to evaluate...”;
INPUT FIRST
IF FIRST=0 THEN
GOTO 100
]ENDIF
PRINT "Enter the Second number to evaluate...";
INPUT SECOND
PRINT "PreSS the key of the operator you want to use..."
PRINT " + - * / w < >...”;
WHILE CHAR="" DO
RUN INKEY(CHAR)
ENDWHILE
PRINT
FLAG=SUHSTR(CHAR,LOOKUP)
ON 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..."
END
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

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 Procedure: weekday

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

DIM X,Y,D,M,CALC:INTEGER; DAY,MONTH:STRING[2]; YEAR:STRING[4]; WEEKDAY (7):STRING[9]
DIM ANUM,BNUM,CNUM,DNUM,ENUM,FNUM,GNUM,HNUM,INUM:INTEGER
PRINT USING "S80 ","Day of the Week Program","For any year after 1752"
PRINT
PRINT "Enter day (e.g. 08): "; \ INPUT DAY
PRINT " Enter month (e.g. 12): "; \ INPUT MONTH
PRINT " Enter year (e.g. 1986): "; \ INPUT YEAR
Y=VAL(YEAR) \M=VAL(MONTH) \D=VAL(DAY)
FOR X=1 TO 7
READ WEEKDAY(X)
NEXT X
ANUM= INT(.6+1/M)
BNUM=Y-ANUM
CNUM=M+12*ANUM
DNUM=BNUM/100
ENUM=INT(DNUM/4)
FNUM=INT(DNUM)
GNUM-INT(5*HNUM/4)
HNUM=INT(13*(CNUM+1)/5)
INUM=HNUM+GNUM-FNUM+ENUM+D-1
INUM-INUM-7*INT(INUM/7)+1
PRINT
PRINT "The day of the week on "; M; "/"; D; "/"; Y; " i5..."; WEEKDAY (INUM)
DATA “Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
END

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 Procedure: integer

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

DIM T: INTEGER
FOR T=1 TO 1 0
R=RNDC50)-25
PRINT R,INTCR)
NEXT T
END

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

Sample Procedure: produce

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.

DIM T,U:INTEGER
DIM NUM,NUM1,NUM2,TABLE,PROCNAME:STRING
PROCNAME=SHOW
TABLE="123456789AHCDEF"
FOR T=8 TO 15
FOR U=1 TO 15
NUM1=MID$(TABLE,T,1)
NUM2=MID$(TABLE,U,1)
NUM=NUM1+NUM2 			(* parameter to pass to Show.
RUN PROCNAME(NUM)
NEXT U
NEXT T
KILL "PROCNAME" 	Q		(* remove Show from the workspace.
END

Procedure: SHOW

PARAM NUM:STRING
SHELL "DISPLAY "+NUM
END

LAND: Returns the logical AND of two numbers

Syntax: LAND(numl,num2)

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 Procedure: questions

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

DIM QUESTION;STRING[68]; T;INTEGER; X,STORAGE;BYTE
DIM ANSWER;STRING[1]
X-1
FOR T=1 TO 8
READ QUESTION
PRINT QUESTION; " (Y/N)? ";
GET #0,ANSWER
PRINT
IF 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.
ENDIF
X=X#2
NEXT T
RUN summary(STORAGE)
END
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"
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 Procedure: firstname

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

DIM NAMES:STRING; FIRSTNAME:STRING[10]
PRINT "Here are the first names:"
FOR T=1 TO 10
READ NAMES
POINTER=SUHSTR(" ",NAMES) (* find space between first and last names.
FIRSTNAME=LEFT$(NAMES,POINTER-1) 	(* extract first name,
PRINT FIRSTNAME 					(* print first name.
NEXT T
END
DATA "Joe Blonski","Mike Marvel","Hal Skeemish","Fred Laungly"
DATA "Jane Mistey","Wendy Paston","Martha Upshong","Jacqueline Rivers"
DATA "Susy Reetmore","Wilson Creding"

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 Procedure: longname

The following procedure uses LEN to determine which name in a list is longest.

DIM NAMES,LNAME:STRING; LONGEST,LENGTH:INTEGER
NAMES-"" \LNAME="" \LENGTH=0 \LONGEST=0
FOR T=1 TO 10
READ NAMES
LENGTH=LEN(NAMES)
IF LONGEST<LENGTH THEN
LONGEST=LENGTH
LNAME=NAMES
ENDIF
NEXT T
PRINT "The longest name is "; LNAME; " with "; LONGEST; " characters,"
END
DATA "Joe Blonski","Mike Marvel","Hal Skeemish","Fred Laungly"
DATA "Jane Misty","Wendy Paston","Martha Upshong","Jacqueline Rivers"
DATA "Susy Reetmore","Wilson Creding

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.

Examples:

LET A = 5
LET A := H
ANSWER = A * H
LET NAME$ :_ "JOE"
NAME $ = FIRSTNAME$ + " " + LASTNAME$

Sample Procedure: getint

This procedure uses LET to assign a random value to the variable R.

DIM T: INTEGER
FOR T=1 TO 10
LET R=RND(50)-25
PRINT R,INT(R)
NEXT T
END

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 Procedure: questions

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

DIM QUESTION;STRING[60]; T;INTEGER; X,STORAGE;BYTE
DIM ANSWER;STRING[1]
X=1
FOR T=1 TO 8
READ QUESTION
PRINT QUESTION; " (Y/N)? ";
GET #O,ANSWER
PRINT
IF ANSWER="y" OR ANSWER="Y" THEN
STORAGE=LOR(STORAGE,X) 			(* Answer is yes, set bit to 1,
ELSE
STORAGE=LAND(STORAGE,LNOT(X)) 		(* Answer is no, set bit to 0,
END I F
X=X*2
NEXT T
PRINT STORAGE
RUN summary(STORAGE)
END
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"

LOG: Returns natural logarithm

Syntax: LOG(nUmber)

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 Procedure: logs

This procedure calculates the natural log and the log to base 10 of the values 1-7.

DIM NUM,T:INTEGER
FOR T=1 TO 7
PRINT "The LOG of "; T; " to the natural base = "· LOG(T)
PRINT "The LOG of "; T; " to base 1 0 = "; LOG10(T)
PRINT
NEXT T
END

LOG10: Returns base 10 logarithm

Syntax: LOG 10(number)

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 Procedure: logs

This procedure calculates the natural log and the log to base 10 of the values 1-7.

DIM NUM,T:INTEGER
FOR T=1 TO 7
PRINT "The LOG of "; T; " to the natural base = "· LOG(T)
PRINT "The LOG of "; T; " to base 10 = "; LOG10(T)
PRINT
NEXT T
END
LOOP/ENDLOOP
Establishes/Closes a loop
**Syntax:** LOOP
Statement(s)
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

PRINT COUNT
X=COUNT/2
ENDLOOP
INPUT X,Y
LOOP
EXITIF X<0 THEN

END ENDEXIT

PRINT "X became 0 first"
X = X-1
EXITIF Y=0 THEN

END ENDEXIT

PRINT "Y became 0 first"
Y=Y-1
ENDLOOP

Sample Procedure: bandit

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.

DIM FRUIT1,FRUIT2,FRUIT3,STAKE:INTEGER; FRUIT(10):STRING[G]
STAKE=25
PRINT \ PRINT "You have $"; STAKE; " to play with."
FOR T=1 TO 10
READ FRUIT(T)
NEXT T
LOOP
FRUIT1=RNDC9)+1 \FRUIT2=RNDC9)+1 \FRUIT3=RNDC9)+1
PRINT FRUIT(FRUIT1); " "; FRUIT(FRUIT2); " "; FRUIT(FRUIT3)
IF FRUIT(FRUIT1)=FRUIT(FRUIT2) AND FRUIT(FRUIT1)=FRUIT(FRUIT3) THEN
STAKE=STAKE+10
ELSE
IF FRUIT(FRUIT1)=FRUIT(FRUIT2) OR FRUIT(FRUIT2)=FRUIT(FRUIT3) THEN
STAKE=STAKE+2
ELSE
IF FRUIT(FRUIT1)=FRUIT(FRUIT3) THEN
STAKE=STAKE+1
ELSE STAKE=STAKE-1
ENDIF
ENDIF
ENDIF
EXITIF STAKE<1 THEN
PRINT
PRINT "You're Busted...Hetter go home."

Procedure: questions

DIM QUESTION:STRING[60]; T:INTEGER; X,STORAGE:BYTE
DIM ANSWER:STRING[1]
X=1
FOR T=1 TO 8
READ QUESTION
PRINT QUESTION; " (Y/N)? ";
GET #O,ANSWER
]PRINT
IF ANSWER="y" OR ANSWER="Y" THEN
STORAGE=LOR(STORAGE,X)
ELSE
STORAGE=LAND(STORAGE,LNOT(X))
ENDIF
X=X*2
NEXT T
PRINT STORAGE
RUN summary(STORAGE)
END
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

LXOR: Returns logical XOR of two numbers

Syntax: LXOR(valuel, value2

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 5 = Binary 0101 Decimal 6 = Binary 0110 0101

LXOR 0110
= 	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. value2: 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
ENDEXIT
PRINT "Your Stake is now $"; STAKE; "."
PRINT
PRINT
INPUT "Press ENTER to pull again...",Z$
ENDLOOP
END
DATA "ORANGE","APPLE","CHERRY","LEMON","BANANA"
DATA "PEAR", "PLUM","PEACH","GRAPE","APRICOT"

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 Procedure: summary

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

DIM T: INTEGER; A,H,X,TEST,TEST2:BYTE; SUMMARY:STRING[50]
PARAM STORAGE:BYTE
A=0 \H=0
PRINT \ PRINT
PRINT "The following is a summary of the questionnaire answers:"
PRINT
PRINT "The surveyee: "
X=1
FOR T=1 TO 8
TEST=LAND(STORAGE,X)
READ SUMMARY
IF TEST>0 THEN
PRINT TAB(10); SUMMARY
ENDIF
X=X*2
NEXT T
IF LAND(STORAGE,128)>0 THEN
A =1
ENDIF
]IF LAND(STORAGE,64)>0 THEN
B =1
ENDIF
TEST2=LXOR(A,B)
IF TEST2=1 THEN
PRINT "This computer owner either uses the computer"
PRINT "more than two hours a day or shares it with others."
PRINT "This is a heavy use situation."
ENDIF
TEST2=LAND(A,B)
IF TEST2=1 THEN
PRINT "This computer user uses the computer more than two”
PRINT "hours per day and shares it with others. This is a"
PRINT "super heavy use situation."
ENDIF
END
DATA "Uses more than one computer"
DATA "Plays games"
DATA "Uses the computer for word processing"
DATA "Uses the computer for business"
DATA "Keeps a Color Computer at home"
DATA "Keeps a Color Computer at the office"
DATA "Uses the computer more than two hours a day"
DATA "Shares the computer with others"

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 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 Procedure: reverse

This procedure reverses a word or phrase you type. MID$ reads each character in your phrase from the end to the beginning.

DIM PHRASE:STRING; T,BEGIN:INTEGER
PRINT "Type a word or phrase you want to reverse:";
PRINT
INPUT PHRASE
BEGIN=LEN(PHRASE)
PRINT "This is how your phrase looks backwards:"
FOR T=BEGIN TO 1 STEP -1
PRINT MID$(PHRASE,T,1);
NEXT T
PRINT
END

MOD: Returns modulus of a division

Syntax: MOD(numberl,number2)

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,5)

Sample Procedure: stardown

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.

DIM T: INTEGER
SHELL "TMODE PAU=0"
FOR T=1 TO 100
ON MOD(T,8)+1 GOSUB 10,20,30,40,50,60,70,80
NEXT T
SHELL "TMODE PAU=1"
END
10  PRINT USING "S10^","*" \ RETURN
20  PRINT USING "S10^","**" \ RETURN
30  PRINT USING "S10^","***" \ RETURN
40  PRINT USING "S10^","****" \ RETURN
50  PRINT USING "S10"","*****" \ RETURN
60  PRINT USING "S10^","****" \ RETURN
70  PRINT USING "S10^","***" \ RETURN
80  PRINT USING "S10^","**" \ RETURN
END

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: statements Procedure lines you want to execute within the loop. For more information, see FOR/NEXT/STEP.

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 expression resulting in a Boolean value.

Examples:

DIM TEST:BOOLEAN
WHILE NOT(TEST) DO

ENDWHILE

A=A+1
TEST=A=H

Sample Procedure: readfile

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.

DIM A:STRING[80]
DIM PATH:BYTE
SHELL "DIR > dirfile"
OPEN #PATH,"dirfile":READ
WHILE NOT EOF(#PATH) DO
READ #PATH,A
PRINT A
ENDWHILE
CLOSE #PATH
END
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:

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.

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.

Examples:

10 INPUT "Name of file to create? ",FILENAME

100 PRINT "That file already exists...please choose another name..." GOTO 10

DIM FILENAME:STRING
DIM PATH: INTEGER
ON ERROR GOTO 100
CREATE #PATH,FILENAME:UPDATE
END
END

Sample Procedure: purge

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.

REM Use caution with this procedure
REM He Sure to Specify key characters
REM that exist only in the files you
REM want to delete!
DIM PATH: INTEGER
DIM NAME(100):STRING
DIM WILDCARD:STRING
X=0
OPEN #PATH,"dirfile":READ
WHILE NOT(EOF(#PATH)) DO
X=X+1
READ #PATH,NAME(X)
ENDWHILE
FOR T=1 TO X
PRINT NAME(T),
NEXT T
INPUT "Wildcard Characters...",WILDCARD
FOR T=1 TO X
ON ERROR GOTO 100
IF SUBSTR(WILDCARD,NAME(T))>0 OR WILDCARD="*" THEN
PRINT "DELETING “; NAME(T); "...... "
DELETE NAME(T)
ENDIF
10  NEXT T
END
100  PRINT "*  *  *  ERROR,  "; NAME(T) ; “  cannot be deleted...continuing.
GOTO 10
END
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 results"
PRINT " C3) Try again C4) Start a new program"
INPUT "Type the letter of your-choice: ",CHOICE
ON CHOICE GOSUB 100, 200, 300, 400

Sample Procedure: repeat

This procedure uses MOD to execute repeatedly a sequence of GOSUB commands. A loop of index of 80 causes execution to jump to each line number in the list 10 times.

SHELL "TMODE PAU=0"
DIM T: INTEGER
FOR T=1 TO 80
ON MODCT,8)+1 GOSUB 10,20,30,40,50,60,70,80
NEXT T
SHELL "TMODE PAU=1"
END
10  PRINT USING "S10^","*" \ RETURN
20  PRINT USING "S10^","**" \ RETURN
30  PRINT USING "S10^”,”***" \ RETURN
40  PRINT USING "S10^","****" \ RETURN
50  PRINT USING "S10^”,”*****" \ RETURN
60  PRINT USING "S10^","****" \ RETURN
70  PRINT USING "S10^","***" \ RETURN
80  PRINT USING "S10^","**" \ RETURN
END
ON/GOTO Jump to line number on a
specified condition

Syntax: ON pos GOTO linenum [,linenum,...]

Function: Transfers procedure control to the line number located at position pos in the list of line numbers immediately following the GOTO 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/GOTO you must have numbered lines to match the line numbers in the list.

Parameters:

pos: An integer value in a range from 1 to the number of items in the list following GOTO. linenum: Any numbered line in the procedure.

Examples:

PRINT "You can now: (1) End the program (2) Print the results"
PRINT " 			(3) Try again 		(4) Start a new program"
INPUT "Type the letter of your choice: ",choice
ON CHOICE GOTO 100, 200, 300, 400

Sample Procedure: bicalc

This procedure converts decimal numbers to binary. It uses ON GOTO to execute the operation you select from a menu: Convert a number, display the result of all conversions, or end the program.

DIM  NUMBER,NUM,X,STORAGE:INTEGER;  BI:STRING;
ARRAY(50,2):STRING
COUNT=0
10  BI="" \NUMHER=0 \NUM=0 \X=0 \STORAGE=0
INPUT "Number to convert to binary ",NUMBER
IF NUMBER=0 THEN END
ENDIF
NUM=LOG10(NUMHER)/.3
NUM=2^NUM \STORAGE=NUMBER
REPEAT
X=NUMBER/NUM
IF X>0 THEN BI=BI+"1"
NUMHER=MOD(NUMHER,NUM)
ELSE BI=BI+"0"
ENDIF
NUM=NUM/2
UNTIL NUM<=1
IF NUMHER>0 THEN
BI=BI+”1"
ELSE^BI=BI+"0"
ENDIF
PRINT STORAGE; " = "; BI; " in binary."
PRINT
COUNT=COUNT+1
ARRAY(COUNT,1)=STR$(STORAGE)
ARRAY(COUNT,2)=BI
12  PRINT "Do you want to: C1) Convert another number."
PRINT "                                (2) Disp1ay all ca1cu1ations thus far."
PRINT "                                (3) End the program."
INPUT "Enter 1, 2, or 3...",choice
ON choice GOTO 10,20,30
END
20  FOR T=1 TO COUNT
PRINT ARRAY(T,1); " = "; ARRAY(T,2)
NEXT T
GOTO 12
30  PRINT \ PRINT " Program Terminated"
END

OPEN: Opens a path to a device

Syntax: OPEN # path,"pathlist" [access model][+ access model][+...]

Function: Opens an input/output path to a disk file or to a device. When you open a file, you can select one or more of the following access modes: Mode Function READ Lets you read (receive) data from a file or device but does not allow you to write (send) data. WRITE Lets you write data to a file or device but does not allow you to read data. UPDATE Lets you both read from and write to a file ordevice. EXEC Specifies that the file you want to access is in the current execution directory. DIR Specifies that the file you want to access is a directory-type file.

Parameters:

path: The variable in which Basic09 stores the number of the newly opened path. pathlist: The route to the file or device to be opened, including the filename if appropriate. access: mode The type of access the system is to allow for the file or device. Use a plus symbol to specify more than one type of access. Notes: The access mode defines the direction of I/O transfers. Because OS-9 files are byte-addressed and are unformatted, you can set up the filing system you want for a particular application. Your system can read the data contained in a file as single bytes or in groups of any size you want. You can expand a file using PRINT, WRITE, or PUT statements to write beyond the current end-of-file.

Examples:

OPEN #TRANS,"transportation":UPDATE
OPEN #SPOOL,"/user4/report":WRITE
OPEN #OUTPATH,name$:UPDATE+EXEC

Sample Procedure: reader

This procedure opens a path to both the SYS directory on Drive /DO and the error message file.

DIM A:STRING[80]
DIM PATH:BYTE
OPEN #PATH,"/D0/SYS/ERRMSG":READ
WHILE EOF(#PATH)<>TRUE DO
READ #PATH,A
PRINT A
ENDWHILE
CLOSE #PATH
END

OR: Performs a Boolean OR operation

Syntax: operand l OR operand2

Function: Performs an OR operation on two or more values, returning a Boolean value of either TRUE or FALSE.

Parameters:

operand1, operand2: Either numeric or string values.

Examples:

PRINT A>3 OR B>3
PRINT A$="YES" or B$="YES"

Sample Procedure: uppercase

This procedure asks you to type a word or phrase, then converts all lowercase characters to uppercase. It uses OR to test for a character in your word or phrase that is outside of the ASCII values for lowercase letters. If it is, the character does not need converting.

DIM PHRASE,NEWSTRING:STRING[80]; CHARACTER: STRING[1]; T,X:INTEGER
NEWSTRING="" \PHRASE=""
PRINT "Type a phrase in lowercase and I will make it uppercase."
INPUT PHRASE
FOR T=1 TO LEN(PHRASE)
CHARACTER=MID$(PHRASE,T,1)
X=ASC(CHARACTER)
IF X<97 OR X>122 THEN
NEWSTRING=NEWSTRING+CHARACTER
ELSE
X=X-32
NEWSTRING=NEWSTRING+CHR$(X)
ENDIF
NEXT T
PHRASE=NEWSTRING
NEWSTRING=""
PRINT PHRASE
END
PARAME stablishes variables to receive from another procedure

Syntax: PARAM variable[,...] [: type] [; variable] [,... ] [: type] [...]

Function: Defines the parameters that a called procedure expects to receive from the procedure that calls it. When using PARAM, be sure that the total size of each parameter in the calling procedure's RUN statement is the same as the defined size in the called procedure's PARAM statement.

Parameters:

variable: A simple variable, an array structure, or a complex data structure.

type: Byte, Integer, Real, Boolean, String, or user defined. Notes: Basic09 checks the size of each parameter to prevent accidental access to storage other than that assigned to the parameter. However, Basic09 does not check that parameters are of the proper type. In most cases you must be sure that types evaluated in RUN statements match the types defined in the PARAM statements.

However, because Basic09 does not perform type checking, it is possible to perform useful but normally illegal type conversions of identically-sized data structures. For example, you could pass a string of 80 characters to a procedure expecting a byte array of 80 elements. Each character in the string is assigned a corresponding position in the array.

You declare simple arrays by using the variable name, without a subscript, in a PARAM statement You can declare several variables of the same type by separating them with commas. To separate variables of different types, follow each type group with a colon, the type name, and then a semicolon. If you do not include a maximum length for a string variable enclosed in brackets following the type, like this:

DIM name:string[251]

Basic09 uses a default length of 32 characters for strings. You can declare shorter or longer lengths, to the capacity of Basic09's memory. Arrays can have one, two, or three dimensions. The PARAM format for dimensioned arrays is the same as for simple variables except you must follow each array name with a subscript, enclosed in parentheses, to indicate its size. The maximum array size is 32767. Arrays can be either of the standard Basic09 type, or of a user-defined type. To create your own data types for simple variables, arrays, and complex data structures, see TYPE.

Examples:

PARAM NUMBER: INTEGER
PARAM NAME:STRING[25];ADDRESS:STRING[30];ZIP: INTEGER
PARAM NO1,NO2,NO3:REAL;NO4,NO5,NO6:INTEGER;NO7:BYTE

Sample Procedure: convert

The first procedure asks you to enter a decimal number. Then, it asks you to choose whether you want to convert the number to binary or hexadecimal. Depending on your choice, the procedure calls (using RUN) either a procedure named Binary or a procedure named Hex. It passes the number you typed to the appropriate procedure for conversion

DIM NUMBER,CHOICE:INTEGER
PRINT USING "S80^"; "Hexadecimal – Binary Conversion Program"
PRINT
10  INPUT "Number to convert...",NUMBER
IF NUMBER=0 THEN
END
ENDIF
INPUT "Choose: (1) Binary or (2) Hex...",CHOICE
ON CHOICE GOTO 20,30
20  RUN BINARY(NUMBER)
GOTO 10
30  RUN HEX(NUMBER)
GOTO 10
END

Procedure: binary

DIM NUM,X,STORAGE:INTEGER; BI :STRING; ARRAY(50,2):STRING
PARAM NUMBER:INTEGER
COUNT=0
BI="" \NUM=0 \X=0 \STORAGE=0
NUM=LOG10CNUMBER)/.3
NUM=2^NUM \STORAGE=NUMBER
REPEAT
X=NUMBER/NUM
IF X>0 THEN
BI=BI+"1 "
NUMBER=MOD(NUMBER,NUM)
ELSE
BI=BI+"0"
ENDIF
NUM=NUM/2
UNTIL NUM<=1
IF NUMBER>0 THEN
BI=BI+"1"
ELSE
BI=BI+"0"
ENDIF
PRINT STORAGE; " = "; BI; " in binary."
PRINT
END

Procedure: hex

DIM NUM,X,STORAGE:INTEGER; TABLE,HX:STRING; ARRAY(50,2):STRING
PARAM NUMBER:INTEGER
TABLE="123456789ABCDEF"
HX="" \NUM=0 \X=0 \STORAGE=0
NUM=LOG10(NUMBER)/1.2
NUM=16^NUM \STORAGE=NUMBER
REPEAT
X=NUMBER/NUM
IF X>0 THEN
HX=HX+MID$(TABLE,X,1)
NUMBER=MOD(NUMBER,NUM)
ELSE HX=HX+"0"
ENDIF
NUM=NUM/ 16
UNTIL NUM<=1
IF NUMBER>O THEN
HX=HX+MID$(TABLE,NUMBER,1)
ELSE
HX=HX+"0"
ENDIF
PRINT STORAGE; “ = “; HX; " in hexadecimal."
PRINT
END

PAUSE: Suspends execution and enters Debug

Syntax: PAUSE text

Function: Suspends the execution of a procedure and causes Basic09 to enter the DEBUG mode. If you include text with the PAUSE command, it is displayed on the screen.

Place PAUSE statements in a program temporarily to observe the way in which the procedure operates and to track down programming errors. When the procedure is operating correctly, remove the PAUSE statement. After using DEBUG, you can continue execution of the paused procedure with the CONT command.

Parameters:

text: A message you want PAUSE to display on the screen when Basic09 executes the statement.

Examples:

PAUSE
PAUSE: The array is now full.

PEEK: Returns the value in a memory location

Syntax: PEEK(mem)

Function: Returns the value of a memory byte as a decimal integer. The value returned is in the range 0 to 255. PEEK is the complement of the POKE statement. See also [ADDR].

Parameters:

mem: An integer value representing the location of the memory byte you want to examine. The memory byte is relative to the current process's address space.

Examples:

PRINT PEEKC15250)
MEMVAL = PEEKC4450)

Sample Procedure: lowercase

This procedure asks you to type a phrase in uppercase characters. It then uses ADDR to locate the area in memory where Basic09 stores the phrase. Next, it reads each character from memory with PEEK, converts it to lowercase if necessary, and pokes the new value back into the same location. When the procedure displays the contents of the phrase, it is all lowercase.

DIM LOC,T:INTEGER; PHRASE:STRING[80]
PRINT "Type a phrase in UPPERCASE and I'll make it lowercase."
INPUT PHRASE
LOC=ADDR(PHRASE)
FOR T=LOC TO LOC+LEN(PHRASE)
X=PEEK(T)
IF X>32 AND X<91 THEN
X=X+32
POKE T,X
ENDIF
NEXT T
PRINT PHRASE
END

PI: Returns the value of pi

Syntax: PI

Function: Returns the constant value 3.14159265.

Parameters:*

None

Examples:

PRINT "The area of a circle with a radius of 6 inches is:";PI*6A

Sample Procedure: picalc

This procedure uses the formula (PI + 2)/15 as a basis for calculating a screen position. Taking the sine of the formula, it prints a sine wave of asterisks down the screen.

DIM FORMULA,CALCULATE,POSITION:REAL
SHELL "DISPLAY 0C"
FORMULA=(PI+2)/15
CALCULATE=FORMULA
SHELL "TMODE PAU=0"
FOR T=0 TO 100
CALCULATE=CALCULATE+FORMULA
POSITION=INT(SIN(CALCULATE)*10+16)
PRINT TAB(POSITION); "*"
NEXT T
SHELL "TMODE PAU=1"
END

POKE: Stores a value in a memory location

Syntax: POKE mem, value

Function: Stores a value at the specified memory address, relative to the current process's address space. Mem is an absolute address at which Basic09 stores a byte type value. POKE is the complement of the PEEK statement. You should use care when using POKE. Because it changes the value in memory, a POKE to the wrong portion of memory could cause OS-9, Basic09, or your procedures to malfunction until you reboot the system. See also ADDR.

Parameters:

mem: An integer value representing the location of the memory byte you want to change. value: The value to store in the specified memory location.

Examples:

POKE 1 5250, 1 3

Sample Procedure: lowercase

This procedure asks you to type a phrase in uppercase characters. It then uses ADDR to locate the area in memory where Basic09 stores the phrase. Next, it reads each character from memory, converts it to lowercase if necessary, and uses POKE to store the new value back in the same location. When the procedure next displays the contents of the phrase, it is all lowercase.

DIM LOC,T:INTEGER; PHRASE:STRING[80]
PRINT "Type a phrase in UPPERCASE and I'll make it lowercase."
INPUT PHRASE
LOC=ADDR(PHRASE)
FOR T=LOC TO LOC+LEN(PHRASE)
X=PEEK(T)
IF X>32 AND X<91 THEN
X=X+32
POKE T,X
ENDIF
NEXT T
PRINT PHRASE
END

POS: Returns cursor's column position

Syntax: POS

Function: Returns the current column position of the cursor. Parameters: None

Examples:

PRINT POS

Sample Procedure: wordwrap

This procedure is a simple typing program that uses POS to make sure that words are not split when you type to the end of the screen. After you type 25 characters on a line, the procedure breaks the line at the next space character.

DIM CHARACTER:STRING[1]
PRINT USING "S32^"; "Word Wrap Program"
PRINT USING "S32^"; "Press [CTRL][C] to Exit"
PRINT
SHELL "TMODE -ECHO"
WHILE CHARACTER<>" " DO
GET #1,CHARACTER
PRINT CHARACTER;
IF POS>25 AND CHARACTER=" " THEN
PRINT CHR$(13)
ENDIF
ENDWHILE
SHELL "TMODE ECHO"
END
PRINT 	Displays text
**Syntax:** PRINT [#path] [TAB(pos);] data[;data...]

**Function:** Prints numeric or string data on the video display unless another path is specified.

Parameters:

path: The number corresponding to an opened device or file. If you do not specify path, the default is # 1, the video screen (standard output device). To print to another device or file, first OPEN a path to that file or device (see OPEN). pos: A column number that tells TAB where to begin printing. Specify any number from 0 to the width of your video display. data: Any numeric or string constant or variable. Enclose string constants within quotation marks. All data items must be separated by a semicolon or comma. Notes: If you specify more than one data item in the statement, separate them with commas or semicolons. If you use commas, PRINT automatically advances to the next tab zone before printing the next item. In Basic09, tab zones are 16 characters apart. If you use semicolons or spaces to separate data items, Basic09 prints the items without any spaces between them. Basic09 begins the next print item immediately following the end of the last print item. If you end a print item without any trailing punctuation, PRINT begins printing at the beginning of the next line If the data being printed is longer than the display screen width, PRINT moves to the next line and continues printing the data. TAB causes Basic09 to begin displaying the specified data at the column position specified by TAB. If the output line is already past the specified TAB position, PRINT ignores TAB. You can concatenate items for printing using the plus (+ symbol, for example: print "hello "+name$+" +lastname$.

You must enclose string constants within quotation marks.

PRINT displays REAL numbers with nine or fewer digits in regular format. It displays REAL numbers with more than nine digits in exponential format. For example, 1073741824 is displayed as 1.07374182E+09.

Examples:

PRINT A$
PRINT "Menu Items"
PRINT COUNT
PRINT VALUE,TEMP+Cn/2.5),LOCATION$
PRINT #PRINTER-PATH,"The result i5 ";NUMBER
PRINT #OUTPATH FMT$,COUNT,VALUE
PRINT "what is"+NAME$+`s age? ";
PRINT "INDEX: ";I;TAB(25);"VALUE ";VALUE

Sample Procedure: reverse

This procedure asks you to type a word or phrase, then displays it backwards by reading each character from end to beginning and using PRINT to display it on the screen.

DIM PHRASE,TITLE:STRING; T,BEGIN:INTEGER
DIM INSTRUCTIONS:STRING[43]
TITLE="Word Reversing Program"
INSTRUCTIONS="Type a word or phrase you want to reverse: "
PRINT TITLE
PRINT "____________________________"
WHILE PHRASE<>”” DO
PRINT
PRINT INSTRUCTIONS
INPUT PHRASE
BEGIN=LEN(PHRASE)
PRINT "This is how your phrase looks backwards:"
FOR T=BEGIN TO 1 STEP -1
PRINT MID$(PHRASE,T,1);
NEXT T
PRINT
ENDWHILE
END
PRINT USING Displays formatted text
**Syntax:** PRINT [#path] USING [format,] data[;data...]

**Function:** Prints data using a format you specify. This statement is especially useful for printing report headings, accounting reports, checks, or any document requiring a specific format. USING is actually an extension of the PRINT statement; therefore, the same rules that apply to the PRINT statement also apply to the PRINT USING statement (see PRINT).

Parameters:

path: The number corresponding to an opened device or file. If you do not specify pith, the default is # 1, the video screen (standard output device). To print to another device or file, first OPEN a path to that file or device (see OPEN). format: An expression specifying the arrangement of the displayed data. data: Any numeric or string constant or variable. Always enclose string constants within quotation marks. Each data item must be separated by semicolons or commas. Notes: Each PRINT USING format specifier begins with a single identifier letter that specifies the type of format, as shown in the following table:

B: Boolean format

E: exponential format

H: hexadecimal format

I: integer format

R: real format

S: string format

Follow the identifier letter with a constant number that specifies the field width. This number indicates the exact number of printcolumns the output occupies. It must allow for both the data and any overhead characters, such as sign characters, decimal points, exponents, and so on. Optionally, you can add a justification indicator to the format expression. The indicators are <, >, and ^. The meaning of these indicators varies, depending on the format type in which you use them. See the format type descriptions for specific information. Note: Do not use any spaces within format expressions. The following are the format type descriptions:

Real Use this format for real, integer, or byte type numbers. The total field width specification must include two overhead positions for the sign and decimal point. The field width has two parts, separated by a period. The first part specifies the integer portion of the field. The second part specifies how many fractional digits to display to the right of the decimal point. If a number has more significant digits than the field allows, Basic09 uses the undisplayed digits to round the number within the correct field width. The justification modes are: < Left justify with leading sign and trailing spaces. This is the default if you omit a justification indicator. >ight justify with leading spaces and sign. ^ight justify with leading spaces and trailing sign (financial format). Some examples and their results are:

Exponential Use this format to display real, integer, or byte values in the scientific notation format-using a mantissa and decimal exponent. The field has two parts: the first part must allow for six overhead positions for the mantissa sign, decimal point, and exponent characters. The justification modes are: < Left justify with leading sign and trailing spaces. This is the default if you omit a justification indicator. > Right justify with leading spaces and sign. Some examples and their results are:

PRINT USING 1IR8.2<11,5678.123 5678.12
PRINT USING 1IR8.2>11,5678.123 5678.12
PRINT USING "R8.2>",12.3 12.30
PRINT USING "R8.2>",-555.9 -555.90
PRINT USING "R10.2^",-6722.4599 6722.46-
PRINT USING "E1 2. 3",1 234.567 1.235E+03
PRINT USING "E13.6>",-.001234 -1.234000E-03
PRINT USING "E18. 5>",1 23456789 1.23457E+08

Integer Use this format to display integer, byte, or real type numbers in an integer or byte format. The field width must allow for one position of overhead for the sign. The justification modes are: < Left justify with leading sign and trailing spaces. This is the default if you omit a justification indicator. > Right justify with leading spaces and sign. ^ Right justify with leading sign and zeroes. Some examples and their results are:

Hexadecimal Use this format to display any data type in hexadecimal notation. The field width specification determines the number of hexadecimal characters Basic09 displays. If the data to display is string type, this function displays the ASCII value of each character in hexadecimal. The justification modes are: < Left justify with trailing spaces. This is the default if you omit a justification indicator. > Right justify with leading spaces. ^ Center digits. The number of bytes of memory used to represent data varies according to data type. The following chart suggests field widths for specific data types: Memory Field Width Type Bytes To Specify Boolean and Byte 1 2 Integer 2 4 Real 5 10 String 1 per 2 times the string character length Some examples and their results are:

PRINT USING "I4<",10 10
PRINT USING "I4<",10 10
PRINT USING "I4^",-10 –010
PRINT USING "H4",100 0064
PRINT USING "H4",-1 FFFF
PRINT USING "H81%--,--ABC" 414243

String Use this format to display string data of any length. The field width specifies the total field size. If the string to display is shorter than the field size, PRINT USING pads it with spaces according to the justification mode. If the string to display is longer than the specified field width, PRINT USING truncates the right portion of the string. The justification modes are: < Left justify with trailing spaces. This is the default if you omit a justification indicator. > Right justify with leading spaces. ^ Center characters. Some examples and their results are:

Boolean Use this format to display Boolean expression results. Basic09 converts the result of the expression to the strings "True" or "False." The format and results are identical to STRING formats. The justification modes are: < Left justify with trailing spaces. This is the default if you omit a justifcation indicator. > Right justify with leading spaces. ^ Center characters. If A = 5 and B = 6, some examples and their results are:

Control Specifiers You can also use control specifiers within PRINT USING formats. The three specifiers are: Tn Tab. n specifies a tab column at which to display the next data. Xn Spaces. n specifies a number of spaces to insert. `text' Constant string. text is a string that is constant to the format. An example and its result is:

Address 03E8 Data 64 Repeat You can repeat identical sequences of specifications using parentheses within a format specification. Enclose the group of specifications you wish to repeat, preceded by a repetition count, such as: ”2(X2,r10.5” in place of “X2,R10.5,X2,R10.511” ”2(I2,2(X1,S4))" in place of "I2,X1,S4,X1,S4,I2,X1,S4,X1,S4"

PRINT USING "S9<","HELLO" HELLO
PRINT USING "S9>","HELLO" HELLO
PRINT USING "S9^","HELLO" HELLO
PRINT USING "B9<",A<B True
PRINT USING "B9>",A>B Fa1se
PRINT USING "B9"",A=B Fa1se
PRINT USING "'Address',X1,H4,X4,'Data',X1,H2",1000,100

Sample Procedure: memlook

This program looks at memory locations 32000 to 32010 and displays their contents in decimal, hexadecimal, and binary. PRINT USING formats the display in columns.

DIM NUMBER,T,MEM,VALUE:INTEGER
DIM X,NUM:INTEGER; CHARACTER,BI:STRING
PRINT "  Addr.  Dec.  Hex.  Bin            ASCII"
FOR Z=32000 TO 32010
BI=""
NUMBER=PEEK(Z)
IF NUMBER>0 THEN
GOSUB 100
ENDIF
IF PEEK(Z)<32 THEN
CHARACTER=""
ELSE
CHARACTER=CHR$(PEEK(Z))
ENDIF
IF PEEK(Z)>0 THEN
PRINT USING "I6<,T7,I4<,X2,H4<,X1,S8<,X2,S1",Z,PEEK(Z),PEEK(Z),
BI,CHARACTER
ELSE PRINT USING "I6<,T7,I4<,X2,H4<,X1,S8>,X2,S1",Z,0,0,"0000"," "
ENDIF
NEXT Z
END
100  NUM=LOG10(NUMBER)/.3
NUM=2^NUM
REPEAT
X=NUMBER/NUM
IF X>0 THEN BI=BI+"1"
NUMBER=MOD(NUMBER,NUM)
ELSE BI=BI+"0"
ENDIF
NUM=NUM/2
UNTIL NUM<=1
IF NUMBER>0 THEN
BI=BI+”1”
ELSE BI=BI+"0"
ENDIF
RETURN
END

PUT: Writes to a direct access ale

Syntax: PUT # path, data

Function: Writes a fixed-size binary data record to a file or device. Use PUT to store data in random access files. Although you usually use PUT with files, you can also use it to send data to a device. For information about storing data in random access files, see Chapter 8, "Disk Files". Also, see GET, SEEK, and SIZE.

Parameters:

path: A variable name you chose to use in an OPEN or CREATE statement that stores the number of the path to the file or device to which you are directing data. data: Either a variable containing the data you want to send or a string of data.

Examples:

PUT #PATH,DATA$
PUT INPUT,ARRAY$

Sample Procedure: inventory

This procedure is a simple inventory data base. You type in the information for an item name, list cost, actual cost, and quantity. Using PUT, the procedure stores data in a file named Inventory.

TYPE INV_ITEM=NAME:STRING[25]; LIST,COST:REAL; QTY:INTEGER
DIM INV_ARRAY(100):INV_ITEM
DIM WORK_REC:INV_ITEM
DIM PATH:BYTE
ON ERROR GOTO 10
DELETE "inventory"
10  ON ERROR
CREATE #PATH,"inventory”
WORK_REC.NAME=””
WORK_REC.LIST=0
WORK_REC.COST=0
WORK_REC.QTY=0
FOR N=1 TO 100
PUT #PATH,WORK_REC
NEXT N
L00P
INPUT "Record number? ",recnum
IF recnum<1 OR recnum>100 THEN
PRINT
PRINT "End of Session"
PRINT
CLOSE #PATH
END
ENDIF
INPUT "Item name? ",WORK_REC.NAME
INPUT "List price? ",WORK_REC.LIST
INPUT "Cost price? " WORK_REC.COST
INPUT "Quantity? ",WORK_REC.QTY
SEEK #PATH,(recnum-1)*SIZECWORK_REC)
PUT #PATH,WORK_REC
ENDL00P
END

RAD: Returns trigonometric calculations in radians

Syntax: RAD

Function: Set a procedure's state flag so that a procedure uses radians in SIN, COS, TAN, ACS, ASN, and ATN functions. Because this is the Basic09 default, you do not need to use the RAD statement unless you previously used a DEG statement in the procedure. Parameters: None

Examples:

RAD

Sample Procedure: trigcalc

This program calculates sine, cosine, and tangent for a value you supply. It calculates one set of results in degrees, using DEG, and the second set of results in radians using RAD.

DIM ANGLE:REAL
DEG
INPUT "Enter the angle of two sides of a triangle...",ANGLE
PRINT
PRINT                   Angle","S1NE", -TOSINE" "TAN"
PRINT "                  ----------------------------------------------------“
PRINT "Degrees = "; ANGLE,SIN(ANGLE),COS(ANGLE), TAN(ANGLE)
RAD
PRINT "Radians = "; ANGLE,SIN(ANGLE),COS(ANGLE), TAN(ANGLE)
PRINT
END
READ Reads data from a device or DATA statement
**Syntax:** READ [#path,] varname

**Function:** Reads either an ASCII record from a sequential file or device, or an item from a DATA statement.

Parameters:

Path: A variable containing the path number of the file you want to access. You can also specify one of the standard I/O paths (0, 1, or 2). Varname: The variable in which you want to store the data read from a file, device, or DATA line. Notes: The following information deals with reading sequential disk files: To read file records, you must first dimension a variable to contain the path number of the file, then use OPEN or CREATE to open a file in the READ or UPDATE access mode. The command begins reading records at the first record in the file. After it reads each item, it updates the pointer to the next item. Records can be of any length within a file. Make sure the variable you use to store the records is dimensioned large enough to store each item. If the variable storage is too small, Basic09 truncates the record to the maximum size for which you dimensioned the variable. If you do not indicate a variable size with the DIM statement, the default -is 32 characters. Basic09 separates individual data items in the input record with ASCII null characters. You can also separate numeric items with comma or space character delimiters. Each input record is terminated by a carriage return character The following information deals with reading DATA items:

Each READ command copies an item into the specified variable storage and updates the data pointer to the next item, if any. You can independently move the pointer to a selected DATA statement. To do this, use line numbers with the DATA lines See the DATA and RESTORE commands for more information on using this function of READ.

READ accesses DATA line items sequentially. Each string type item in a DATA line must be surrounded by quotation marks. Items in a DATA line must be separated with commas.

Examples:

READ #PATH,DATA
READ #1,RESPONSE$
READ #INPUT,INDEXCX
FOR T=1 TO 10
READ NAME$(T)
NEXT T
DATA "JIM","JOE","SUE","TINA","WENDY"
DATA "SALL","MICKIE","FRED",”MARV”,”WINNIE”

Sample Procedure: randlist

This procedure puts random values between 1 and 10 into a disk file, then READS the values and uses asterisks to indicate how many times RND selected each value.

DIM SHOW,BUCKET:STRING
DIM T,PATH,SELECT(10),R:INTEGER
BUCKET="************************'I
FOR T=1 TO 10
SELECT(T)=0
NEXT T
ON ERROR GOTO 10
SHELL "DEL RANDFILE"
10  0N ERROR
CREATE #PATH,"randfile":UPDATE
FOR T=1 TO 100
R=RND(9)+1
WRITE #PATH,R
NEXT T
PRINT "Random Distribution"
SEEK #PATH,0
FOR T=1 TO 100
READ #PATH,NUM
SELECT(NUM)=SELECT(NUM)+1
NEXT T
FOR T=1 TO 10
SHOW=RIGHT$(BUCKET,SELECT(T))
PRINT USING "S6<,I3<,S2<,S20<","Number",T,":",SHOW
NEXT T
CLOSE #PATH
END

REM: Inserts remarks in a procedure

Syntax: REM [text] (* [text][*)] Function: Inserts remarks inside a procedure. Basic09 ignores these remarks; they serve only to document a procedure and its functions. Use remarks to title a procedure, show its creation date, show the name of the programmer, or to explain particular features and operations of a procedure.

Parameters:

Text: Comments you want to include within a procedure Notes: You can insert remarks at any point in a procedure. The second form of REM, using parentheses and asterisks, is compatible with Pascal programming structure. When editing programs, you can use the exclamation character "!" in place of the keyword REM. Basic09's initial compilation retains remarks, but the PACK compile command strips them from procedures.

Examples:

REM this is a comment

(* Insert text between parentheses and asterisks*) (* or use only one parenthesis and asterisk

Sample Procedure: copydir

This procedure uses the various forms of REM to explain its operations.

REM Use this program with the
(* GET sample program to *)
(* create a file of directory*)
(* filenames, then copy they*)
(* files to another directory*)
DIM PATH,T,COUNT:INTEGER; FILE,JOH,DIRNAME:STRING
OPEN #PATH,"dirfile":READ (* open the file
INPUT "Name of new directory...",DIRNAME (* get the directory
SHELL "MAKDIR "+DIRNAME (* create a newdirectory
SHELL "LOAD COPY"
WHILE NOT(EOF(#PATH)) DO
READ #PATH,FILE (* get a filename
JOB=FILE+" "+DIRNAME+"/"+FILE (* create the COPY syntax
ON ERROR GOTO 10
PRINT "COPY "; JOB (* display the operation
SHELL "COPY "+JOB ( copy the file
10  0N ERROR
ENDWHILE
CLOSE #PATH
END
REPEAT/UNTIL Establish a loop/Terminates on specific condition
**Syntax:** REPEAT
Procedure lines
UNTIL expression

Function: Establishes a loop that executes the encompassed procedure lines until the result of the expression following UNTIL is true. Because the loop is tested at the bottom, the lines within the loop are executged at least once.

Parameters:

expression: A Boolean expression (returns either True or False). Procedure Statement you want to repeat until expression returns False. Lines

Examples:

REPEAT
COUNT = COUNT+1
UNTIL COUNT > 100
INPUT X,Y
REPEAT
X = X-1
Y = Y-1
UNTIL X<1 OR Y<0

Examples:

The procedure sorts a disk file. In this case, it is written to sort the disk file created by the GET sample program__a directory listing. It uses a REPEAT/UNTIL loop to compare a string in the file with the first string in the file. If the first string is greater than the comparison string, the procedure swaps them.

Procedure: dirsort

DIM BTEMP:BOOLEAN; TEMP,FILES(125):STRTING; TOP,BOTTOM,M,N:INTEGER
DIM T,X,PATH:INTEGER
FOR T=1 TO 125
FILES(T)=””
NEXT T
T=0
OPEN #PATH,:dirfile”:READ
PRINT “LOADING:”
WHILE NOT(EOF(PATH)) DO
T=T+1
READ #PATH,FILES(T)
ENDWHILE
TOP=T
BOTTOM=1
PRINT “SORTING: “;
10  N=BOTTOM
M=TOP
PRINT “.”;
LOOP
REPEAT
BTEMP=FILES(N)<FILES(TOP)
N=N+1
UNTIL NOT(BTEMP)
N=N-1
EXITIF N=M THEN
ENDEXIT
TEMP=FILES(M)
FILES(M)=FILES(N)
FILES(N)=TEMP
N=N+1
EXITIF N=M THEN
ENDEXIT
ENDLOOP
IF N<>TOP THEN
IF FILES(N)<>FILES(TOP) THEN
TEMP=FILES(N)
FILES(N))=FILES(TOP)
FILES(TOP)=TEMP
ENDIF
ENDIF
IF BOTTOM<N-1 THEN
TOP=N-1
GOTO 10
ENDIF
IF N+1<TOP THEN
BOTTOM=N+1
GOTO 10
ENDIF
CLOSE #PATH
DELETE “dirfile”
CREATE #PATH,”dirfile”:WRITE
PRINT
FOR Z=1 TO T
WRITE #PATH,FILES(Z)
PRINT FILES(Z),
NEXT Z
CLOSE #PATH
END

RESTORE: Resets READ pointer

Syntax: RESTORE linenumber

Function: Sets the pointer for the READ command to the specified line number. RESTORE without a line number sets the data pointer to the first data statement in the procedure.

Paramenter: linenumber The line number of the DATA items you want READ to access.

READ assigns the items in a DATA statement to variable storage. When you read an item, the pointer automatically advances to the next item. Using RESTORE you can skip backwards or forwards to data items at a specific line number.

Examples:

RESTORE 100

Sample Procedure: box

This procedure draws a box on the screen. It uses RESTORE to repeat the data in line 20 to create the sides of the box.

DIM LINE:STRING
READ LINE
PRINT LINE
FOR T=1 TO 10
RESTORE 20
READ LINE
PRINT LINE
NEXT T
RESTORE 10
READ LINE
PRINT LINE
10  DATA “------------------------------“
20  DATA “                                      ”
END

RETURN: Returns from subroutine

Syntax: RETURN

Function: Retuens procedure execution to the line immediate following the last GOSUB statement. Parameters: None

Sample Procedure: stars

This procedure draws a design of astgerisks down the display screen. It uses MOD to send execution to a series of PRINT USING routines over and over. Each PRINT USING routine sends execution back to the main routine with a RETURN statement.

DIM T:INTEGER
SHELL “TMODE –PAUSE”
FOR T=1 TO 100
ON MOD(T,8)+1 GOSUB 10,20,30,40,50,60,70,80
NEXT T
SHELL “TMODE PAU=1”
END
10  PRINT USING “S10^”,”*” \ RETURN
20  PRINT USING “S10^”,”**” \ RETURN
30  PRINT USING “S10^”,”***” \ RETURN
40  PRINT USING “S10^”,”****” \ RETURN
50  PRINT USING “S10^”,”*****” \ RETURN
60  PRINT USING “S10^”,”****” \ RETURN
70  PRINT USING “S10^”,”***” \ RETRUN
80  PRINT USING “S10^”,”**” \ RETURN
END

RIGHT$: Returns specified rightmost portion of a string

Syntax: RIGHT$(string,length)

Function: Returns the specified number of characters from the right portion of the specified string. If length is the same as or greater than the number of characters in string, then RIGHT$ returns all of the characters in the string.

Parameters:

String: A sequence of string type characters or a variable containing a sequence of string type characters. Length: The number of characters you want to access.

Examples:

PRINT RIGHT$(“HOTDOG”,3)
PRINT right$(a$,6)

Sample Procedure: lastname

DIM NAMES:STRING: LASTNAME:STRING[10]
PRINT “Here are the last names:”
FOR T=1 TO 10
POINTER=SUBSTR(“ “,NAMES)
POINTER=LEN(NAMES)-POINTER
LASTNAME=RIGHT$(NAMES,POINTER)
PRINT LASTNAME
NEXT T
DATA “Joe Blonski”,”Mike Marvel”,”Hal Skeemish”,”Fred Langly”
DATA “Jane Misty”,”Wendy Paston”,”Martha Upshong”,”Jacqueline Rivers”
DATA “Susy Reetmore”,”Wilson Creding”
END

RND: Returns a random value

Syntax: RND(number)

Function: Returns a random real value in the following ranges: If number = 0 then range = 0 to 1 If number>0 then range = 0 to number The values produced by RND are not truly random numbers, but occur in a predictable sequence. Specifying a number less than 0 begins the sequence over.

Parameters:

number: A numeric constant, variable, or expression.

Examples:

PRINT RND(5)
PRINT RND(A)
PRINT RND(A*5)

Sample Procedure: addition

This procedure presents addition problems for you to solve. It uses RND to select two numbers between 0 and 20.

DIM A,B,ANSWER,C:INTEGER
FOR T=1 TO 5
A=RND(20)
B=RND(20)
C=A+B
PRINT USING “’What is:  ’,13”,A
PRINT USING “’              +  ’,13”,B
PRINT “                  ------“
INPUT “                    ”,ANSWER
IF ANSWER=C THEN
PRINT “CORRECT”
ELSE
PRINT “WRONG”
ENDIF
PRINT
NEXT T
END
RUN execute another procedure

Syntax: RUN procname [(param[,param,…])]

Function: Calls a procedure for execution, passing the specified parameters to the called procedure. When the called procedure ends, execution returns to the calling procedure, beginning at the statement following the RUN statement. RUN can call a procedure existing within the workspace, a procedure previously compliled by the PACK command, or a machine language procedure outside the workspace.

Parameters:

procname: The name of the procedure to execute. The procname can be the literal name of the procedure to execute, or it can be a variable name containing the procedure name. param: One or more parameters that the called procedure needs for execution. The parameters can be variables or constants, or the names of entire arrays or data structures. Notes: You can pass all types of data to a called program except byte type. However, you can pass byte arrays. If a parameter is a constant or expressing, Basic09 passes it by value. That is, Basic09 evaluates the constant or expression and places it in temporay storage. It passes the address of the temporary storage location to the called procedure. The called program can change the passed values, but the changes are not reflected in the calling procedure. If a parameter is the name of a variable, array, or data structure, Basic09 passes it to the called program by reference. That is, it passes the address of the variable storage to the called procrdure. Thus, the value can be changed by the receiving procedure, and these changes are reflected in the calling procedure. If the procedure names by RUN is not in the workspace, Basic09 looks outside the workspace. If it cannot find it there, it looks in the current execution directory for a diskfile with the proper name. If the file is on disk, Basic09 loads and execute it, regardless of whether it is a packed Basic09 program or a machine language program. If the program is a machine language module, Basic09 executes a JSR (jump to subroutine) instruction to its entry point and executes it as 6809 native code. The machine language program returns to the original calling procedure by executing a RTS (return from subroutine) instruction. After you call an external procedure, and no longer need it, use KILL to remove it from memory to free space for other operations. Machine language modules return error status by setting the C bit of the MPU condition code register, and by setting the B register to the appropriate error code.

Examples:

RUN CALCULATE(10,20,ADD)
RUN PRINT(TEXT$)

Sample Procedure: makelist

Makelist creates and displays a list of fruit. Next, it asks you to type a word to insert. After you type and enter a new word,Makelist uses RUN to call a second procedure names Insert to look through the list and insert the new word in alphabetical order. After each insertion, the procedure asks for another word. Press only [ENTER] to terminate the program.
DIM LIST(25),NEWORD,TEMPWORD:STRING[15]
DIM T,LAST:INTEGER
LAST=10
PRINT “This is ytour list…”
FOR T=1 TO LAST
READ LIST(T)
PRINT LIST(T),
LOOP
PRINT
PRINT
INPUT “Type a word to insert…”,NEWORD
EXITIF NEWORD=”” THEN
PRINT
END “I’ve ended the session at your request…”
ENDEXIT
RUN Insert(LIST,NEWORD,LAST)
PRINT
PRINT “This is your new list…”
FOR T=1 TO LAST
PRINT LIST(T)
NEXT T
PRINT
ENDLOOP
DATA “APPLES”,”BANANAS”,”CANTALOPE”
DATA “DATES”,”GRAPES”,”LEMONS”
DATA “MANGOS”,”PEACHES”,”PLUMS”
DATA “PEARS”

Procedure: insert

PARAM LIST(25),NEWORD:STRING[15]
PARAM LAST:INTEGER
DIM TEMPWORD:STRING[15]
DIM T,X:INTEGER
T=1
WHILE NEWORD>LIST(T)DO
T=T+1
ENDWHILE
FOR X=T TO LAST
TEMPWORD=LIST(X)
LIST(X)=NEWORD
NEWORD=TEMPWORD
NEXT X
LAST=LAST+1
LIST(LAST)=NEWORD
END

SEEK: Resets the direct-access file pointer

Syntax: SEEK #path,number

Function: Changes the file pointer address in the disk file. The pointer indicates the location in a file for the next READ or WRITE operation. You usually use SEEK with random access files to move the pointer from one record to another, in any order. You can also use SEEK with sequential access files tp rewind the pointer to the beginning of the file (to the first item or record). For information about storing data in random access files, see Chapter 8. “Disk Files.” Also see PUT, GET, and, SIZE. Paramters: Path A variable name you choose in which Basic09 stores the number of the path it opens to the file you specify. Number The item or record number you weant to access. If you are rewinding a sequenctial, access file, specify a number 0.

Examples:

SEEK #PATH,0
SEEK #OUTFILE,A
SEEK #INDEX,LOCATION*SIZE(INVENTORY)

Sample Procedure: makelist

This procedure creates a file named Test1, then writes 10 lines of data into it. Next, it reads the lines from the file and displays them. It uses SEEK to both store and extract the lines in blocks of 25 characters.

DIM LENGTH:BYTE
DIM LINE:STRING[25]
DIM PATH:BYTE
LENGTH=25
BASE 0
ON ERROR GOTO 10
DELETE “test1”
10  ON ERROR
CREATE #PATH,”test1”:WRITE
FOR T=0 TO 9
READ LINE$
SEEK #PATH,LENGTH*T
PUT #PATH,LINE$
NEXT T
CLOSE #PATH
OPEN #PATH,”test1”:READ
FOR T=9 TO 0 STEP –1
SEEK #PATH,LENGTH*T
GET #PATH,LINE
PRINT LINE
NEXT T
CLOSE #PATH
END
DATA “This is a test line #1”
DATA “This ia a test line #2”
DATA “This ia a test line #3”
DATA “This ia a test line #4”
DATA “This ia a test line #5”
DATA “This ia a test line #6”
DATA “This ia a test line #7”
DATA “This ia a test line #8”
DATA “This ia a test line #9”
DATA “This ia a test line #10”

SGN: Returns a value’s sigh

Syntax: SGN(number)

Function: Determines whether a number’s sign is positive or negative If number is less than 0, then SGN returns –1. If number equals 0, then SGN returns 0. If number is greater than 0, then SGN returns 1.

Parameters:

Number: The value for which you want to determine the sign.

Examples:

PRINT SGN(-22)
PRINT SGN(A)
PRINT SGN(44-A)

Sample Procedure: halfsine

This procedure uses SGN to create half sine waves down the screen. SGN tests when the SIN calculation results are positive.

DIM FORMULA,CALCULATE,POSITION:REAL
SHELL “DISPLAY 0C”
FORMUA=(PI+2)/15
CALCULATE=FORMULA
SHELL “TMODE –PAUSE”
FOR T=0 TO 100
CALCULATE=CALCULATE+FORMULA
POSITION=INT(SIN(CALCULATE)*10+16)
IF SGN(SIN(CALCULATE))>0 THEN
PRINT TAB(POSITION); “*”
ENDIF
NEXT T
SHELL “TMODE PAU=1”
END

SHELL: Forks another shell

Syntax: SHELL ["string"][ + "string"...][ + variable] [ + variable...]

Function: Executes OS-9 commands or programs from within a Basic09 procedure. Using SHELL, you can access OS-9 functions, including multiprogramming, utilities, commands, terminal and input/output control, and so on.

When you use the SHELL command, OS-9 creates a new process to handle the commands you provide. If you specify an operation, Basic09 evaluates the expression and passes it to the shell for execution. If you do not specify an operation, Basic09 temporarily halts, and the shell process displays prompts and accepts commands in the normal manner. In this case, press CTRL BREAK to return to Basic09.

When the shell process terminates, Basic09 becomes active and resumes execution at the statement following the SHELL statement.

Parameters:

string: Any OS-9 command or function. String: constants must be enclosed in quotation marks. Concatenate string constants and string variables using a plus symbol (+ ). variable: Any string variable containing an OS-9 command or function.

Examples:

SHELL "COPY FILE1 FILE2"
SHELL "COPY FILE1 FILE2&"
SHELL "COPY "+FILE$+" "+DIRNAME+"/"FILE$
SHELL "LIST DOCUMENT"
SHELL "KILL "+STR$CN)

Sample Procedure: copyutil

You must use this procedure with the GET sample program. Using the two programs together enables you to copy all the files from one directory to another directory. The GET sample program reads the files in a directory and stores them in a file named Dirfile. This procedure reads the filenames from Dirfile and uses SHELL to copy them to the directory you specify.

DIM PATH,T,COUNT:INTEGER; FILE,JOB,DIRNAME:STRING
OPEN #PATH,"dirfi1e":READ
INPUT "Name of new directory...",DIRNAME
SHELL "MAKDIR "+DIRNAME
SHELL "LOAD COPY"
WHILE NOT(EOF(#PATH)) DO
READ #PATH,FILE
JOB=FILE+" "+DIRNAME+"/"+FILE
ON ERROR GOTO 10
PRINT "COPY "; JOB
SHELL "COPY "+JOB
10  0N ERROR
ENDWHILE
CLOSE #PATH
END

SIN: Returns the sine of a number

Syntax: SIN(number)

Function: Calculates the trigonometric sine of number. You can use the DEG or RAD commands to cause number to represent a value in either degrees or radians. Unless you specify DEG, the default is radians. SIN returns a real number.

Parameters:

number: The angle of two sides of a triangle for which you want to find the ratio.

Examples:

PRINT SIN(4S

Sample Procedure: ratiocalc

This procedure calculates sine, cosine, and tangent values for a number you type.

DEG
DIM ANGLE:REAL
INPUT "Enter the angle of two sides of a triangle...",ANGLE
PRINT
PRINT "Angle","SINE","COSINE”,”TAN”
PRINT “-------------------------------------------------------“
PRINT ANGLE,SIN(ANGLE),COS(ANGLE).,TAN(ANGLE) OPRINT REND

SIZE: Returns the size of a data structure

Syntax: SIZE(variable)

Function: Returns the size in bytes of a variable, array, or data structure. SIZE is especially useful with random access files to determine the size of records to store in a file. You can also use SIZE to determine the size of variable storage for other purposes. SIZE returns the size of assigned storage, not necessarily the size of a string. For example, if you dimension a variable for 15 characters, and assign a 10-character string to it, SIZE returns 15, not 10. SIZE returns the total size of arrays. That is, it returns the number of elements multiplied by the size of the elements.

Parameters:

variable: The variable, array, or data structure for which you want to find the size.

Examples:

RECORDLENGTH = SIZE(A$)
PRINT "YOUR NAME IS STORED IN A "; SIZE(NAME$); " CHARACTER STRING."

Sample Procedure: inventory

This procedure creates a simple inventory, stored in a file named Inventory. It uses SIZE to calculate the size of each element to be stored in the file, and to move the pointer to the beginning of each record's storage space

TYPE INV_ITEM=NAME:STRING[25]; LIST,COST:REAL; QTY: INTEGER
DIM INV_ARRAY(100):INV_ITEM
DIM WORK_REC:INV_ITEM
DIM PATH:BYTE
ON ERROR GOTO 10
DELETE "inventory"
10  0N ERROR
CREATE #PATH,"inventory"
WORK_REC.NAME="
WORK_REC.LIST= 0
WORK_REC.COST= 0
WORK_REC.QTY=0
FOR N=1 TO 100
PUT `PATH,WORK-REC
NEXT N
LOOP
INPUT "Record number? ",recnum
IF recnum<1 OR recnum>100 THEN
PRINT
PRINT "End of Session"
PRINT
CLOSE #PATH
END
ENDIF
INPUT "Item name? ",WORK_REC.NAME
INPUT "List price? ",WORK_REC.LIST
INPUT "Cost price? ",WORK_REC.COST
INPUT "Quantity? ",WORK_REC.QTY
SEEK #PATH,(recnum-1)*SIZE(WORK_REC)
PUT #PATH,WORK_REC
ENDLOOP
END
SQ Returns the value of a number raised to the power of 2
**Syntax:** SQ(number)

**Function:** Calculates the value of a number raised to the power of 2.

Parameters:

number: The number you want raised to the power of 2.

Examples:

PRINT SQC188)
PRINT PI·SQ(R)

Sample Procedure: sinedown

This procedure uses SQ in a formula that positions asterisks on the screen in a sine wave pattern.

DIM FORMULA,CALCULATE,POSITION:REAL
SHELL "DISPLAY 0C"
FORMULA=(PI+2)/15
CALCULATE=FORMULA
SHELL "TMODE PAU=0"
FOR T=0 TO 200
CALCULATE=CALCULATE+SQ(FORMULA)
POSITION=INT(SIN(CALCULATE)*12+16)
PRINT TAB(POSITION); "*"
NEXT T
SHELL "TMODE PAU=1"
END
SQR/SQRT Returns the square root of a number
**Syntax:** SQR(number)
SQRT(number)
**Function:** Calculates the square root of a number. SQR and SQRT serve the same function.

Parameters:

number: The number for which you want the square root.

Examples:

PRINT SQR(188)
PRINT PI*SQRT(R)

Sample Procedure: sqrdown

This procedure uses SQRT in a formula to position asterisks on the screen in a sine wave pattern.

DIM FORMULA,CALCULATE,POSITION:REAL
SHELL "DISPLAY 0C"
FORMULA=PI/15
CALCULATE=FORMULA
SHELL "TMODE PAU=0"
FOR T=0 TO 200
CALCULATE=CALCULATE+SQRT(FORMULA).
POSITION=INT(SIN(CALCULATE)*12+16)
PRINT TAB(POSITION); "*"
NEXT T
SHELL "TMODE PAU=1"
END
STEP Establishes the size of increments in a FOR loop
**Syntax:** FOR variable = init val TO end val [STEP value] [procedure statements] NEXT variable

**Function:** STEP provides an increment value in a FOR/NEXT loop. If you do not specify a STEP value, the loop steps in increments of 1.
Basic09 executes the lines following the FOR statement until it encounters a NEXT statement. Then it either increases or decreases the initial value by 1 (the default) or by the value given by STEP. If you give the loop an initial value that is greater than the final value, and specify a negative value for STEP, the loop decreases from the initial value to the 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 be executed Statements within the loop.

Examples:

FOR COUNTER = 1 to 100 STEP.S
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 Procedure: reverse

This procedure reverses the order of characters in a word or phrase you type. It uses STEP to decrement a counter that points to each character in the string in reverse order.

DIM PHRASE:STRING; T,BEGIN:INTEGER
PRINT "Type a word or phrase you want to reverse:";
PRINT
INPUT PHRASE
BEGIN=LEN(PHRASE)
PRINT "This is how your phrase looks backwards:"
FOR T=BEGIN TO 1 STEP –1
PRINT MID$(PHRASE,T,1);
NEXT T
PRINT
END

STOP: Terminates a procedure

Syntax: STOP ["string"]

Function: Causes a procedure to cease execution, print the message "STOP Encountered", and return control to Basic09's command mode. You can also specify additional text to display when Basic09 encounters STOP. Use stop when you want a procedure to terminate without entering the DEBUG mode.

Parameters:

string: Text to display when STOP executes.

Examples:

STOP "Program terminated before completion."
IF RESPONSE = "Y" THEN STOP "Program terminated at your request." ENDIF

STR$: Converts numeric data to string data

Syntax: STR$(number)

Function: Converts a numeric type to a string type. This lets you display the number as a string or use string operators on a number. The conversion replaces the numeric values with the ASCII characters of the number. STR$ is the inverse of the VAL function.

Parameters:

number: Any numeric-type data.

Examples:

PRINT STR$(1010)
DIM I:INTEGER
I=44
PRINT STR$(I)
DIM B:BYTE
B=001
PRINT STR$(H)
DIM R:REAL
R=1234.56
PRINT STR$(R)

Sample Procedure: bignum

This procedure calculates an exponential value, then adds the necessary number of zeroes to convert it to standard notation. It uses STR$ to convert the number you type to a string type value so that it can use string functions to add the zeroes.

DIM C,PLACES,H,SIGN:STRING; EX,COUNT,NEWCOUNT, DECIMAL:INTEGER
DIM NEW,ZERO,NEWEST:STRING[100]
COUNT=-1
ZERO="000000000000000000000000000000000000"
NEW="" \NEWEST=""
INPUT "What number do you want to raise to the power of 14?...", NUM   A=NUM^14
B=STR$(A)
EX=SUBSTR("E",H)
SIGN=MID$(H,EX+1,1)
PLACES=RIGHT$(B,LEN(B)-EX-1)
FOR T=1 TO LEN(B)
C=MID$(H,T,1)
IF C="." THEN
DECIMAL=0
GOTO 10
ENDIF
DECIMAL=DECIMAL+1
IF C="E" THEN 100
NEW=NEW+C
10  NEXT T
100  NEWCOUNT=VAL(PLACES)-DECIMAL
NEW=NEW+LEFT$(ZERO,NEWCOUNT+1)
FOR T=LEN(NEW) TO 1 STEP –1
COUNT=COUNT+1
NEWEST=MID$(NEW,T,1)+NEWEST
IF MOD(COUNT,3)=2 AND T>,1 THEN
NEWEST=","+NEWEST
ENDIF
NEXT T
[  PRINT NUM; " to the power of 14 = "; a
PRINT "_ "; NEWEST
END

SUBSTR: Searches for specified characters in a string

Syntax: SUBSTR(targetstring,searchstring)

Function: Searches for the first occurrence of targetstring within searchstring and returns the numeric value of its location. SUBSTR counts the first character in searchstring as character Number 1. Therefore, if you searched for the string "worth" in the string "Fortworth", SUBSTR returns a value of 5. If SUBSTR cannot find targetstring, it returns a value of 0.

Parameters:

targetstring: The group of characters you want to locate. searchstring: The string in which you want to find targetstring.

Examples:

PRINT SUBSTR("THREE","ONETWOTHREEFOURFIVESIX")
X=SUBSTR(" ",FULLNAME$)

Sample Procedure: lastname

This procedure selects the last name from a string containing both a first name and a last name. It uses SUBSTR to find the space between the two names in order to determine where the last name begins.

DIM NAMES:STRING; LASTNAME:STRING[10]
PRINT "Here are the last names:"
FOR T=1 TO 10
READ NAMES
POINTER=SUBSTR(" ",NAMES)
POINTER=LEN(NAMES)-POINTER
LASTNAME=RIGHT$(NAMES,POINTER)
PRINT LASTNAME
NEXT T
DATA "Joe Blonski","Mike Marvel","Hal Skeemish","Fred Laungly"
DATA "Jane Misty","Wendy Paston","Martha Upshong","Jacqueline Rivers"
DATA "Susy Reetmore","Wilson Creding"
END

SYSCALL: Executes an OS-9 System Call

Syntax: SYSCALL callcode registers

Function: Lets you execute any OS-9 system call from Basic09. Use this command to directly manipulate your system or data or to directly access devices. Be careful! Used improperly, SYSCALL can cause undesirable results you might unintentionally format a disk or destroy disk or memory data. Before using SYSCALL, you should be familiar with assembly language programming and should understand the system call information in the OS-9 Technical Reference manual. The OS-9 Technical Reference manual provides information about all OS-9 system calls. To pass required register values to the SYSCALL command, create a complex data structure that contains values for all registers. Fbr example:

TYPE REGISTERS=CC,A,B,DP:HYTE; X,Y,U:INTEGER DIM REGS:REGISTERS DIM CALLCODE:BYTE
The complex data type REGISTERS contains values for all registers. Unless you specifically assign values to variables (for instance, REGS.CC, REGS.A, and REGS.B in the previous example), they contain random values. See the TYPE command for further information.

Parameters:

callcode: is the request code of the system call you wish to use. All system call codes are referenced in the OS-9 Technical Reference manual. registers: is a list of the register entry values required for the system call you are using. Examples: see "Sample Programs." Sample Programs: The following programs set up a data type (REGISTERS) for the register variables. Before executing SYSCALL, the procedures store the required register entry values in the complex data structure REGS. The procedures also establish CALLCODE as a variable to hold the request code of the system call you want to use. The Writecall procedure uses the string variable TEST to store text that it writes to the screen through Path 0 (the standard output path) using System Call $8A, I$Write. Before the procedure calls I$Write, it stores the appropriate path number (0) in Register A. The ADDR command calculates the address of the variable TEST, and the LEN command determines the length of the variable. The procedure stores these two values in Registers X and Y. The Readcall uses System Call $8B, I$ReadLn to perform a function that is the opposite of Writecall. Readcall establishes TEST as a string variable into which it writes the characters you type. Because the length of TEST is restricted to ten characters (DIM TEST: STRING[ 1 0 1 ), the terminal bell sounds if you attempt to type more than 10 characters. Pressing [ENTER] terminates the call and the procedure prints the contents of TEST the characters you typed

Procedure: WriteCall

TYPE REGISTERS=CC,A,B,DP:BYTE; X,Y,U:INTEGER
DIM REGS:REGISTERS
DIM PATH,CALLCODE:BYTE
DIM TEST:STRING[50]
TEST="This is a test of I$Write,,Sy5tem call $8A..."
REGS.A=0
REGS.X=ADDR(TEST)
REGS.Y=LEN(TEST)
CALLCODE=$8A
RUN SYSCALL(CALLCODE,REGS)
PRINT
END

Procedure: Readcall

TAB Causes PRINT to jump to the specified column Syntax: TAB(number) Function: Causes PRINT to display the next PRINT item to display in the column specified by number. If the cursor is already past the desired tab position, Basic09 ignores TAB. Use POS to determine the current cursor position when displaying characters on the screen. Screen display columns are numbered from 1, the leftmost column, to a maximum of 255. The size of Basic09 output buffer varies according to the stack size. You can also use TAB with PRINT USING statements.

TYPE REGISTERS=CC,A,B,DP:BYTE; X,Y,U:INTEGER
DIM REGS:REGISTERS
DIM PATH,CALLCODE:BYTE
DIM TEST:STRING[10]
REGS.A=0
REGS.X=ADDR(TEST)
REGS.Y=10
CALLCODE=$8B
RUN SYSCALL(CALLCODE,REGS)
PRINT
PRINT TEST
END

Parameters:

number: The column at which you want PRINT to begin.

Examples:

PRINT TAB(20);TITLE$
PRINT TAH(X);ITEMNUMBER;ITEM$

Sample Procedure: sinewave

This procedure uses asterisks to simulate a sine wave on the screen. It uses TAB to position each asterisk in the proper location.

DIM FORMULA,CALCULATE,POSITION:REAL
SHELL "DISPLAY 0C"
FORMULA=(PI+2)/15
CALCULATE=FORMULA
SHELL "TMODE PAU=0"
FOR T=0 TO 200
CALCULATE=CALCULATE+SQ(FORMULA)
POSITION=INT(SIN(CALCULATE)*12+16)
PRINT TAB(POSITION); "*"
NEXT T
SHELL "TMODE PAU=1"
END

TAN: Returns the tangent of a value

Syntax: TAN(number)

Function: Calculates the trigonometric tangent of number. Using DEG or RAD, you can specify the measure of the angle (number) in either degrees or radians. Radians are the default units.

Parameters:

number: The angle for which you want to find the tangent.

Examples:

PRINT TAN(45)

Sample Procedure: ratiocalc

This procedure calculates sine, cosine, and tangent values for a number you type.

DEG
DIM ANGLE:REAL
INPUT "Enter the angle of two sides of a triangle...",ANGLE
PRINT “-------------------------------------------------------------“
PRINT "Angle","SINE","COSINE","TAN"
PRINT ANGLE,SIN(ANGLE),COS(ANGLE),TAN(ANGLE)
PRINT
end
TRIM$ Removes spaces from the end of a string
**Syntax:** TRIM$(string)

**Function:** Removes any trailing spaces from the end of the specified string. This function is particularly useful for trimming records you recover from a random access file.

Parameters:

string: The string or string variable from which you wish to remove trailing spaces.

Examples:

PRINT TRIM$(A$)
GET A$,B$,C$
PRINT TRIM$(A$),TRIM$(B$),TRIM$(C$)

Sample Procedure: namestor

This program takes names you type and puts them in a random access disk file. Because random access files use the same amount of storage for each item, short names are pfd with extra spaces. When reading the names back from the file, the procedure uses TRIM$ to remove these extra spaces.

DIM NAMES,TEMP1,NAME(100):STRING[26]; FIRST,LAST: STRING[15];INITIAL:STRING[1]
DIM PATH,T:INTEGER
NAMES=""
ON ERROR GOTO 10
DELETE "nameliSt"
10  ON ERROR
CREATE #PATH,"nameliSt":UPDATE
FOR T=1 TO 100
NAME(T)
NEXT T
T=0
L00P
INPUT "First Name: ",FIRST
EXITIF FIRST="" THEN
CLOSE #PATH
GOTO 100
ENDEXIT
INPUT "Initial: ",INITIAL
INPUT "Last: ",LAST
T=T+1
NAME(T)=FIRST+" "+INITIAL+" "+LAST
PUT #PATH,NAME(T)
SEEK #PATH,T*26
ENDLOOP
100  OPEN #PATH,"namelist":READ
PRINT \ PRINT
PRINT "Lastname","Firstname","Initial
REM Print underline (40 characters)
PRINT "_________________________________________________”
PRINT
SEEK #PATH,O
T=0
WHILE NOT(EOF(#PATH)) DO
GET #PATH,NAMES
T=T+ 1
NAMES=TRIM$(NAMES)
X=SUHSTR(" ",NAMES)
FIRST=LEFT$(NAMES,X-1)
TEMP1=RIGHT$(NAMES,LEN(NAMES)-X+1)
INITIAL=MID$(TEMP1,2,1)
LAST=RIGHT$CTEMP1,LENCTEMP1)-3)
PRINT LAST,FIRST,INITIAL
SEEK #PATH,T*26
ENDWHILE
CLOSE #PATH
END
TRON/TROFF Turns on/off trace function
**Syntax:** TRON
TROFF

Function: Turns on or off the Basic09 trace mode. When trace is turned on (TRON), Basic09 decompiles and displays each statement in a procedure before execution. Basic09 also displays the result of each expression after evaluation. This function lets you follow program flow and is helpful in debugging and analyzing the execution of a procedure. After the procedure is debugged, remove the TRON statement. If you want to view only a portion of a procedure's execution, surround that portion with TRON and TROFF. Tracing begins immediately after the TRON statement and ends at the TROFF statement. The rest of the program executes normally.

Parameters: None

Examples:

TRON

TROFF

H$="00000000000000000000"+B$
N=1 +LEN(B$)
FOR I=4 TO 1 STEP –1
N=N-4
A(I)=VAL(MID$(B$,N,4)
NEXT I

TRUE: Returns a Boolean TRUE value

Syntax: variable = TRUE

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

Parameters:

variable: The Boolean storage unit you want to set to True.

Examples:

DIM TEST:HOOLEAN
TEST=TRUE

Sample Procedure: quiz

This procedure asks five questions. If your answer is correct, it stores the Boolean value TRUE in a Boolean type variable. If your answer is incorrect,.it stores the Boolean value FALSE in the variable.

DIM REPLY,VALUE:BOOLEAN; ANSWER:STRING[1]; QUESTION:STRING[80]
FOR T=1 TO 5
READ QUESTION,VALUE
PRINT QUESTION
PRINT "(T) = TRUE              (F) = FALSE"
PRINT "Select T or F:    ";
GET #1,ANSWER
IF ANSWER=”T” THEN
REPLY=TRUE
ELSE
REPLY=FALSE
ENDIF
IF REPLY=VALUE THEN
PRINT \ PRINT "That's Correct...Good Show!"
ELSE
PRINT "Sorry, you're wrong...Hetter Luck next time."
ENDIF
PRINT \ PRINT \ PRINT
NEXT T  
DATA "In computer talk, CPU stands for Central Packaging Unit.", FALSE
DATA "The actual value of 64K is 65536 bytes.",TRUE
DATA "The bits in a byte are normally numbered 0 through 7.",TRUE   DATA "HASIC09 has four data types.",FALSE
DATA "The LAND function is a Boolean type operator.",FALSE
END

TYPE: Defines a data type

Syntax: TYPE name = typedeclar [; typedeclar[;...]]

Function: Defines new data types (complex data structures). New data types are vectors (one-dimensional arrays) of previously defined types. Structures created by TYPE differ from arrays in that they can consist of elements of different types, and Basic09 accesses elements by field names rather than by an indexed position.

Parameters:

Name: The name you select for the new data type. typedecrar: One or more type declarations, which can consist of field names, type declarations, and sub scripts. Separate different types or different lengths of string declarations with semicolons. Notes: Complex data structures allow you to create data types that are appropriate for a specific task. You can organize, read, and write associated data naturally. Also, Basic09 establishes and defines element positions at compilation time. This saves time and overhead at run time because Basic09 can access the elements of a data structure faster than it can access the elements of an array. When you define new data structures using TYPE, you can can include any of the five existing data types (string, real, integer, byte, and Boolean), or you can include data structure types that you previously defined with TYPE. This means that your structures can be simple or very complex, such as non-rectangular data lists or trees. TYPE does not create storage. You create storage using the DIM statement, after using TYPE. To access elements of a data structure, use the field name as well as any appropriate element index. For more information on creating and using complex data types, see "Complex Data Types" in Chapter 6.

Examples:

TYPE LIBRARY=TITLE,AUTHOR,PUBLISHER:STRING[25];

REFERENCE: INTEGER

DIM BOOK(500):LIBRARY
TYPE PARTS=ITEM,LOCATION:STRING[20]; CAT:REAL;

QUANTITY;INTEGER

DIM INVENTORY(1000):PARTS

Sample Procedure: books

This procedure builds an array to contain a book reference list, including the book title, the author's name, the publisher, and a reference number. It does so by using TYPE to create a special data structure to store all the information for each book.

TYPE LIBRARY=TITLE,AUTHOR,PUBLISHER:STRING[30]; REFERENCE:INTEGER
DIM BOOKS(100):LIBRARY
T=0
L00P
T=T+ 1
INPUT "BOOK TITLE...",BT$
BOOKS(T).TITLE=BT$
EXITIF BOOKS(T).TITLE="" THEN
GOTO 100
ENDEXIT
INPUT "Book Author...”BA$
BOOKS(T).AUTHOR=BA$
INPUT "Book Publisher...",BP$
BOOKS(T).PUBLISHER=BP$
INPUT "Reference Number...”,BOOKS(T).REFERENCE
ENDLOOP
100  FOR X=1 TO T-1
PRINT BOOKS(X).TITLE; “, “; BOOKs(X).AUTHOR; “, “,
BOOKS(X).PUHLISHER; ", “; BOOKS(X).REFERENCE
NEXT X
END

UNTIL: Terminates a REPEAT loop on specified condition

Syntax: REPEAT procedure lines

UNTIL expression

Function: Ends a REPEAT loop. REPEAT establishes a loop that executes the encompassed procedure lines until the result of the expression following UNTIL is true. Because the loop is tested at the bottom, the lines within the loop are executed at least once.

Parameters:

procedures: Statements you want to execute in the loop. lines: expression A Boolean expression (the result must be either True or False).

Examples:

REPEAT
COUNT = COUNT+1
UNTIL COUNT > 100
INPUT X,Y
REPEAT
X = X-1
Y = Y-1
UNTIL X<1 OR Y<0

See REPEAT for more information.

USING: Formats PRINT output

Syntax: PRINT [#path] USING [format,] data[;data...]

Function: Prints data using a format you specify. This statement is especially useful for printing report headings, accounting reports, checks, or any document requiring a specific format.

USING is actually an extension of the PRINT statement. The same rules that apply to the PRINT statement also apply to the PRINT USING statement (see PRINT).

Parameters:

path: The number to an opened device or file. If you do not specify path the default is #1, the video screen (standard output device). To print to another device or file, first OPEN a path to that file or device (see OPEN). format: An expression specifying the arrangement of the displayed data. data: Any numeric or string constant or variable. Always enclose string constants within quotation marks. Separate all data items with semicolons or commas. See PRINT USING for more information.

VAL: Converts string data to numeric data

Syntax: VAL(string)

Function: Converts string-type data to numeric-type. VAL is the inverse of the STR$ function. It returns the real value represented by the characters in a string. If any character in the specified string is not numeric, Basic09 returns an error.

Parameters:

string: An ASCII string containing one or more of the following characters: 0123456789. + $-.

Examples:

PRINT VAL(123)
A$="44.66"
PRINT VAL(A$)

Sample Procedure: bignum

This procedure calculates an exponential value, then adds the necessary number of zeroes to convert it to standard notation. It uses STR$ to convert the original number to a string, then uses VAL to convert the exponent into a value to determine the correct decimal place.

DIM C,PLACES,B,SIGN:STRING; EX,COUNT, NEWCOUNT, DECIMAL:INTEGER
DIM NEW,ZERO,NEWEST:STRING[100]
COUNT=-1
ZERO="000000000000000000000000000000000000"
NEW="" \NEWEST=""
INPUT "What number do you want to raise to the power of 14?...",NUM
A=NUM^14
B=STR$CA)
EX=SUBSTR("E",H)
SIGN=MID$(H,EX+1,1
PLACES=RIGHT$(B,LEN(B)-EX-1)
FOR T=1 TO LEN(B)
C=MID$(B,T,1)
IF C="." THEN
DECIMAL=0
GOTO 10
ENDIF
DECIMAL=DECIMAL+1
IF C="E" THEN 100
NEW=NEW+C
10  NEXT T
100  NEWCOUNT=VAL(PLACES)-DECIMAL
NEW=NEW+LEFT$(ZERO,NEWCOUNT+1)
FOR T=LEN(NEW) TO 1 STEP -1
COUNT=COUNT+1
NEWEST=MID$(NEW,T,1)+NEWEST
IF MOD(COUNT,3)=2 AND T>1 THEN
NEWEST=","+NEWEST
ENDIF
NEXT T
PRINT NUM; " to the power of 14 = "; A
PRINT "= "; NEWEST
END
WHILE/DO/ENDWHILE Establishes a loop
**Syntax:** WHILE expression DO
procedure lines
ENDWHILE
**Function:** Establishes a loop that executes the encompassed procedure lines while the result of the expression following WHILE is true. Because the loop is tested at the top, the lines within the loop are never executed unless the expression is true.

Parameters:

expression: A Boolean expression (has a result of True or False). procedure: Program lines to execute if the expression is true lines.

Examples:

WHILE COUNT < 12 DO COUNT = COUNT+1 ENDWHILE

Sample Procedure: copyutil

You must create a file of directory names using the GET sample program before you can use the following procedure. Copyutil uses the filenames created by the GET sample program to copy a directoty's files to another directory you specify. You must specify a directory name that does not exist. Copyutil uses a WHILE/DO/ENDWHILE loop to continue copying until Basic09 reaches the end of the file.

DIM PATH,T,COUNT:INTEGER; FILE,JOB,DIRNAME:STRING
OPEN #PATH,"dirfile":READ
INPUT "Name of new directory...",DIRNAME
SHELL "MAKDIR "+DIRNAME
SHELL "LOAD COPY"
WHILE NOT(EOF(#PATH)) DO
READ #PATH,FILE
JOB=FILE+" "+DIRNAME+"/"+FILE
ON ERROR GOTO 10
PRINT "COPY "; JOB
SHELL "COPY "+JOB
10  ON ERROR
ENDWHILE
CLOSE #PATH
END
WRITE Writes data to a sequential file or device
**Syntax:** WRITE [#Path,] data

Function: Writes an ASCII record to a sequential file or to a device.

Parameters:

path: A variable containing the path number of the file or device to which you want to send data. Path: can be one of the the standard I/O paths (0, 1, 2). data: The data you want to send over the specified path. Notes:

The following information deals with writing sequential disk files:

To write file records, you must first dimension a variable to contain the path number of the file, then use OPEN or CREATE to open a file in the WRITE or UPDATE access mode. Records can be of any length within a file. Individual data items in the input record are separated by ASCII null characters. You can also separate numeric items with comma or space character delimiters. Each input record is terminated by a carriage return character.

Examples:

WRITE #PATH,DATA$
WRITE #1,RESPONSE$
WRITE #OUTPUT,INDEX(X)
OPEN #PATH,"namefile":WRITE
FOR T=1 TO 10
READ NAME$
WRITE #PATH, NAME$
NEXT T
CLOSE #PATH
DATA "JIM", "JOE","SUE","TINA","WENDY"
DATA "SALL", "MICKIE","FRED","MARV","WINNIE"

Sample Procedure: randlist

This procedure selects 100 random values between 1 and 10. It uses WRITE to place the values into a disk file. Next, it reads the values from the file and uses asterisks to indicate how many times RND selected each value.

DIM SHOW,BUCKET:STRING
DIM T,PATH,SELECT(10),R:INTEGER
BUCKET="************************”
FOR T=1 TO 10
SELECT(T)=0
NEXT T
ON ERROR GOTO 10
SHELL "DEL RANDFILE"
10   ON ERROR
CREATE #PATH,"randfile":UPDATE
FOR T=1 TO 100
R=RND(9)+1
WRITE #PATH,R
NEXT T
PRINT "Random Distribution"
SEEK #PATH,0
FOR T=1 TO 100
READ #PATH,NUM
SELECT(NUM)=SELECT(NUM)+1
NEXT T
FOR T=1 TO 1 0
SHOW=RIGHT$(BUCKET,SELECT(T))
PRINT USING "S6<,I3<,S2<,S20<","Number",T,":",SHOW
NEXT T
CLOSE #PATH
END

XOR: Returns the exclusive OR of two values

Syntax: operand1 XOR operand2

Function: Performs the logical exclusive OR operation on two or more values, returning a value of either TRUE or FALSE.

Parameters:

operand1, operand2: Boolean values or expressions (that result in values of True or False).

Examples:

PRINT 02 XOR H>3
PRINT A$="YES" XOR H$="YES"

Sample Procedure: draw5traw

This procedure lets two people type numbers until one of them guesses the number that the computer picks. It uses XOR to determine that one of the numbers typed is the correct number, but not both.

DIM NUM1,NUM2,R:INTEGER; A:BOOLEAN
PRINT "This program will help you pick"
PRINT "between two people. Choose who will be"
PRINT "Person 1 and who will be Person 2."
PRINT "Then, enter numbers between 1 and 10"
PRINT "when requested."
PRINT
R=RND(1 0
10  INPUT "Person 1, type a number and press ENTER...",NUM1
INPUT "Person 2, type a number and press ENTER...",NUM2
A=NUM1=R XOR NUM2=R
IF A=FALSE THEN
PRINT "You'll have to try again..."
PRINT
GOTO 10
ENDIF
IF NUM1 =R THEN
PRINT "You win, Person 1"
ENDIF
IF NUM2=R THEN
PRINT "You win, Person 2"
ENDIF
PRINT "The Number was..."; R
END
Basic09__											       Reference
11- PAGE 155

Clone this wiki locally