80-Bus News

  

Summer 1985 · Volume 4 · Issue 2

Page 13 of 31

nasty Beeb programs! An additional, useful facility is that text can be put after the backslash — a subtle form of REM, and, as in MBASIC, two or more statements on one line must be separated by a colon.

IF REPT = 0 \ Check for repetition
THEN GOTO 999: PRINT"REPEATING TEST"

The statement can start anywhere on the line — but it is obviously better to use the first 80 columns.

Data I/O

Both BASICs use the conventional PRINT statement with semi-colon or comma separators; in CBASIC, the comma indicates a move to the next printing field which is every 20th print position and the semi-colon leaves one space after the last printed item and then starts printing again. PRINT USING, WIDTH and TAB are also supported by both but 3 statements, Lprinter, Console and POS are specific to CBASIC. Lprinter directs all PRINT statement output to the printer until it is cancelled by the Console statement which routes it back to the screen. Lprinter assumes a print WIDTH of 132 characters unless a lower figure is set (e.g. 80):

Lprinter Width 80

Console assumes a screen width of 80 characters unless otherwise directed.

The POS function is used to identify how many characters have been printed or displayed on a line — useful if you want to see how much space remains. I haven’t used this facility very often!

File handling

in CBASIC there are two types of file, sequential and relative. Their use is rather more straightforward than in MBASIC. The sequential file type is better in terms of disk space usage but the relative file can be read or written to at random since it assigns a fixed space to each possible record. The following remarks apply broadly to both types of file but OPENing or CREATEing relative files involves the RECL parameter in which the record length must be specified:

100 OPEN “A: ADDRESS .LIS” RECL 128 AS 3

Files are opened using CREATE, OPEN or FILE statements and closed by CLOSE (and CHAIN or STOP if these statements occur in a program). CREATE, as its name suggests, sets up a new file, deleting any previous file with the same name, OPEN — well, it just opens a file which has already been created in the directory. FILE is very useful since it will CREATE a new file and OPEN it if it does not currently exist — and it will OPEN a file for I/O if it exists. All these commands can be used to operate more than one file at a time.

OPEN and CREATE have the same syntax, but FILE does not need the identifier to be specified — it does this automatically:

OPEN "B: TEDIOUS.DOC" AS 2
CREATE "A: TEST.DOC AS 1
FILE "A: DAVEHUNTSBITS"

in the first two cases, a file and drive are specified and given a numeric identifier — thus TEDIOUS.DOC was originally set up on disk B and has the identifier 2 — which will be used for subsequent file operations using READ # and PRINT #:
the file on drive A called Davehuntsbits will be assigned 3 as its identifier if it was in the same program; this is because it is the third file to be specified.

READ #2:A$ - reads string variable
                A$ from file 2 which in
                this example, is TEDIOQUS.DOC
PRINT #1;A$ - writes the same string
                variable to file 1 – TEST.DOC

PRINT USING # is a very useful facility if you have a number of different types of output format to include; both PRINT # and PRINT USING # are limited to a maximum number of 20 file identifiers! To CLOSE a file, simply type CLOSE <file identifier> — very neat and just like MBASIC.

Other useful statements are DELETE <identifier> which enables one to delete files when they are no longer required in a program and Initialize which allows one to change a disk without causing the system to become bewildered or risking the scrambling of directories. One can also RENAME a file, determine its SIZE in 1 Kbyte increments, or employ the IF END # statement to do something mind-boggling when the contents of a file have been read and Marvin or whatever you call your machine is about to become seriously confused!

RENAME (NEWFILENAMES$,OLDFILENAME$)
PRINT SIZE("FILENAME$"}
IF END  2 THEN 999 \STOP THE PROGRAM

CBASIC defaults to a record length of 128 bytes for RECL; additionally, one can specify the data buffer length and sector length using the BUFF and RECS parameters; these follow the numeric file identifier. Further information on file handling can be gleaned from the Guide.

Numerical operations

The major differences between the two BASICs are in the field of relational operators (less than, greater than etc.). The conventional combinations of <, > and = are supplemented by letters:

Page 13 of 31