BASIC09 Command Reference l 11
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:
.~2tX2,r1 0.5)"
in place of
IIX2,R1 0.5,X2,R10.511
--2C I2,2CX1 ,S4))"
in place of
"I2,X1 ,S4,X1 ,S4, I2,X1 ,
S4,X1 ,S4"
Sample Program:
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.
PROCEDURE memlook
pDIM NUMHER,T,MEM,VALUE:INTEGER
pDIM X,NUM:INTEGER; CHARACTER ,HI :STRING
OPR I NT "DAddr ODec .0Hex.[1BinE100=ASCI I"
OFOR Z=32000 TO 32010
OH I = ""
ONUMHER=PEEKCZ)
OIF NUMBER>0 THEN
OGOSUH 1 0 0
OENDIF
OIF PEEKCZ)<32 THEN
OCHARACTER=""
OELSE
OCHARACTER=CHR$CPEEKCZ))
REND I F
OIF PEEKCZ)>0 THEN
OPRINT USING "I6<,T7,I4<,X2,H4<,X1,S8<,X2,S1",Z,
PEEKCZ),PEEKCZ),HI,CHARACTER
DELSE PRINT USING "I6<,T7,I4<,X2,H4<,X1,S8>,X2,
S1",Z,0,0,"0000"," "
DENDIF
ONEXT Z
REND
BASIC09 Reference
1 000NUM=LOG1 0CNUMHER)/ . 3
ONUM=2^NUM
pREPEAT
FIX=NUMBER/NUM
OIF X>0 THEN HI=HI+"1"
ENUMHER=MODCNUMHER,NUM)
pELSE HI=HI+"0"
OENDIF
ONUM=NUM/2
OUNTIL NUM<=1
pIF NUMBER>0 THEN
OBI =BI
+111 11
pELSE HI=HI+"0"
REND I F
ORETURN
REND
11-128
BASIC09 Command Reference l 11
PUT
Writes to a direct access
ale
Syntax: PUT # pa th, da to
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 Program:
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.
PROCEDURE inventory
OTYPE INV-ITEM=NAME:STRINGL253; LIST,COST:REAL;
,i'~ QTY: INTEGER
ED IM INV-ARRAYC1 00): INV-ITEM
OD I M WORK-.REC : I NV-ITEM
ODIM PATH:HYTE
DON ERROR GOTO 10
11-129
BASIC09 Reference
DELETE "inventory"
100ON ERROR
pCREATE #PATH,"inventory" ~.,,~
pWORK-REC. NAME=1111
pWORK-REC. L I ST=0
OWORK-REC. COST=0
OWORK-REC. QTY=0
OFOR N=1 TO 1 00
pPUT #PATH,WORK-REC
ONE XT N
pL00P
DINPUT "Record number? ",recnum
OI F recnum<1 OR recnum)-1 00 THEN
OPRINT
DPR I NT "End of Se55 ion"
OPRINT
OCLOSE #PATH
REND
DENDIF
pINPUT "Item name? ",WORK-REC. NAME
OINPUT "List price? ",WORK-REC.LIST
DINPUT "Cost price? " WORK-REC. COST
]INPUT "Quantity? ",WORK-REC.QTY
OSEEK *PATH,Crecnum-1)*SIZECWORK-REC)
pPUT *PATH,WORK-REC
pENDL00P
REND
11-130
BASIC09 Command Reference / 11
RAD
Returns trigonometric calculations in
radians
tax: 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 Program:
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.
PROCEDURE trigcalc
ODIM ANGLE:REAL
ODEG
DINPUT "Enter the angle of two sides of a
triangle...",ANGLE
OPRINT
OPRINT "[10[1[1[10=Angle","S1NE", -TOSINE" "TAN"
OPR I NT "OOOOOOOOO------_---------------------------
------------------
OPRINT "Degrees = "; ANGLE,SINCANGLE),COSCANGLE),
TANCANGLE)
GRAD
OPRINT "Radians = "; ANGLE,SINCANGLE),COSCANGLE),
TANCANGLE)
OPRINT
REND
11-131
BASIC09 Reference
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
varname
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).
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:
e 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.
0
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.
11-132
BASIC09 Command Reference / 11
The following information deals with reading DATA items:
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.
· 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.
Examples:
READ #PATH,DATA
READ #1,RESPONSE$
READ #INPUT,INDEXCX)
FOR T=1 TO 1 0
READ NAME$CT)
. NEXT T
DATA "JIM", "JOE","SUE","TINA","WENDY"
DATA "SALL", "MICK I E", "FRED", --MARV--, --WI NNIP-
11-133
BASIC09 Reference
Sample Program:
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.
PROCEDURE randlist
ODIM SHOW,HUCKET:STRING
pDIM T,PATH,SELECTC10),R:INTEGER
OHUCKET="************************'I
OFOR T=1 TO 1 0
OSELECTCT)=0
ONEXT T
DON ERROR GOTO 10
OSHELL "DEL RANDFILE"
1000N ERROR
OCREATE #PATH,"randfile":UPDATE
OFOR T=1 TO 100
OR=RNDC9)+1
OWRITE #PATH,R
ONEXT T
OPRINT "Random Distribution"
OSEEK #PATH,O
OFOR T=1 TO 100
DREAD #PATH,NUM
OSELECTCNUM)=SELECTCNUM)+1
ONEXT T
OFOR T=1 TO 1 0
OSHOW=RIGHT$CHUCKET,SELECTCT))
OPRINT USING "S6<,I3<,S2<,S20<","Number",
T,":",SHOW
ONEXT T
OCLOSE #PATH
REND
11-134
BASIC09 Command Reference l 11
REM
Inserts remarks in a procedure
Syntax: RE M
[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
Notes:
Comments you want to include within a
procedure
· 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.
0
BASIC09's initial compilation retains remarks, but the
PACK compile command strips them from procedures.
Examples:
REM this is a comment
C* Insert text between parentheses and
asterisks*)
C* or use only one parenthesis and asterisk
11-135
BASIC09 Reference
Sample Program:
This procedure uses the various forms of REM to explain its
operations.
PROCEDURE copydir
OREM Use this program with the
00 GET sample program to
0
00 create a file of directory)
00 filenames, then copy they)
0(* files to another directory)
ODIM PATH,T,COUNT:INTEGER; FILE,JOH,DIRNAME:STRING
OOPEN #PATH,"dirfile":READ (* open the file
DINPUT "Name of new directory...",DIRNAME (* get the directory
OSHELL "MAKDIR "+DIRNAME (* create a newdirectory
OSHELL "LOAD COPY"
OWHILE NOT(EOF(#PATH)) DO
DREAD #PATH,FILE (* get a filename
OJOH=FILE+" "+DIRNAME+"/"+FILE (* create the COPY syntax
DON ERROR GOTO 10
OPRINT "COPY "; JOB (* display the operation
OSHELL "COPY "+JOB ( copy the file
1000N ERROR