Note that in file I/O, when you read an ASCII character 0, the file routines will
return an empty string, so the safeguard listed above is necessary in these cases.
If a string is set to ASCII character 0 using the CHR$ function, it will have a length
of 1 and ASC will work properly on it.
This is the opposite of ASC, and returns a single-character string
character whose ASCII code is given. The code must be between 0 and 255, or an ILLEGAL
QUANTITY ERROR will result.
This command completes and closes any files used by OPEN
statements. The number following CLOSE is the file number to be closed, as specified
in the corresponding OPEN statement. Any file that is opened
in a program should be closed before the program ends. When writing to a file, not
closing it properly could result in the file being lost.
CMD sends the output which normally would go to the screen (i.e., PRINT
statements, LISTs, but not POKEs
onto the screen) to another device instead. This could be a printer, a data
file on tape or disk, or any other standard Commodore file. This device or file must
be OPENed first. The CMD command must be followed by a number or
numeric variable referring to the file. The string, if present, is sent before any
other text, and is useful for prepending a title to the text.
OPEN 1,4 OPENs device #4, which is the printer
CMD 1 All normal output now goes to printer
LIST The program listing now goes to
the printer, not the screen
To send output back to the screen, issue a PRINT# command to
send a blank line to finish off any unfinished lines, then CLOSE
the file. Any error will revert output back to the screen. Devices are not CLOSEd; this
must be done explicitly.
CONT will not work if you have changed or added lines to the program,
or if the program halted due to an error, or if you caused an error before
trying to restart the program. In these cases you will get a CAN'T CONTINUE
ERROR.
This statement stores information in a list of items which is to be used by READ
statements. Items may be numeric values or text strings, and items are
separated by commas. String items need not be inside quote marks unless
they contain space, colon, or comma. If two commas have nothing between
them, the value will be READ as a zero for a number, or an empty string.
DATA 12, 14.5, "HELLO, MOM", 3.14, PART1
The placement of DATA statements inside the program is not important, and
these lines don't have to be RUN in order for the data to be available to
READ statements. Thus, they are usually placed at the end of a program
listing.
See the READ statement for a description of how the
item list is handled.
This statement works with the NEXT statement to
repeat a section of the program a set number of times. The FOR statement
is the start point of this loop, and the variable is initialized to the numeric
value before the TO keyword, and will be increased by the STEP number
(1 if STEP is omitted) each time the loop is run, until the variable reaches the
value after the TO keyword. The STEP value may be positive or negative, and
may be integral or fractional. The entire loop is run at least once in all
cases.
10 FOR L = 1 to 10 STEP .1
20 PRINT L
30 NEXT L
The above program will print out 100 numbers from 1 to 10 in increments of .1.
This statement is similar to GOTO, except the computer
remembers which program line it last executed before the GOSUB. When a line with a
RETURN statement is encountered, the program
jumps back to the statement immediately following the GOSUB. This is
useful if there is a routine in your program that occurs in several parts of the
program. Instead of typing the routine over and over, execute GOSUBs each
time the routine is needed.
LIST Shows all lines
LIST 10- Shows only from line 10 until end
LIST 10 Shows only line 10
LIST -10 Shows lines from beginning until 10
LIST 10-20 Shows line from 10 to 20, inclusive
If the LOAD command is encountered inside a program, the BASIC interpreter will
start executing the freshly loaded program from the first line. If flag is non-zero
during a LOAD inside a program, the data will be loaded to the address specified
in the file, and execution of the current program will restart. This is useful for loading
data into memory without the use of DATA statements.
LOAD Reads in the next program on tape
LOAD "HELLO" Searches tape for program called HELLO,
and loads program, if found
LOAD A$ Looks for program whose name is in the variable A$
LOAD "HELLO",8 Looks for program called HELLO on the disk drive
LOAD "*",8 Looks for first program on disk
The NEW command can also be used as a BASIC program statement. When the
program reaches this line, the program is erased. This is useful if you
want to leave everything neat when the program is done.
NEXT is always used in conjunction with the FOR statement.
When the program reaches a NEXT statement, it checks the FOR statement
to see if the limit of the loop has been reached. If the loop is not finished, the
loop variable is increased by the specified STEP value. If the loop is
finished, execution proceeds with the statement following NEXT.
NEXT may be followed by a variable name, or list of variable names,
separated by commas. If there are no names listed, the last loop started
is the one being completed. If variables are given, they are completed in
order from left to right.
10 FOR X = 1 TO 100: NEXT
20 FOR X = 1 TO 5: FOR Y = 1 TO 5: PRINT X ; Y: NEXT Y,X
This command turns the GOTO and GOSUB
commands into special versions of the IF statement. ON is followed
by a formula, which is evaluated. If the result of the calculation is one,
the first line on the list is executed; if the result is 2, the second line
is executed, and so on. If the result is 0, negative, or larger than
the list of numbers, the next line executed will be the statement
following the ON statement.
Following the device number may be a third number, separated again by a comma,
which is the secondary address. In the case of the cassette, this is 0 for read,
1 for write, and 2 for write with end-of-tape marker. In the case of the
disk drive, this is 0 for read, 1 for write, 2-14 for either read or write, and 15 for
the command channel. When 2-14 are used on the disk, the filename
options ",W", ",R", and ",A" specify write, read, or append, respectively.
In the printer, the secondary address controls features like
expanded printing. See your printer's manual for details.
10 OPEN 1,0 OPENs the SCREEN as a device
20 OPEN 2,1,0,"D" OPENs the cassette for reading,
file to be searched for is D
30 OPEN 3,4 OPENs the printer
40 OPEN 4,8,15 OPENs the data channel on the disk
Once a file has been opened, the CLOSE,
CMD, GET#,
INPUT#, PRINT#
statements can be used with the filenumber specified, and the system
variable ST is activated.
There are a few differences between this statement and PRINT.
PRINT# is followed by a number, which refers to the device or data file previously
OPENed. This number is followed by a comma and a list to be printed. The
comma and semicolon have the same effect as they do in PRINT. Please note
that some devices may not work with TAB and SPC.
READ is used to assign information from DATA statements to variables,
so the information may be put to use. Care must be taken to avoid READing
strings to numeric variables, which will give a TYPE MISMATCH ERROR.
When reading strings, all leading and trailing spaces are truncated, unless the
spaces reside in quotation marks.
10 READ NM$, PH, A$
20 DATA "JOHN DOE", 5551212, SOME GUY
REMark is a note to whomever is reading a LIST of the program. It may
explain a section of the program, or give additional instructions. REM
statements in no way affect the operation of the program, except to add
to its length. REM may be followed by any text.
This statement is always used in conjunction with GOSUB.
When the program encounters a RETURN, it will go to the statement immediately
following the most recent GOSUB command. If no GOSUB was previously issued, a
RETURN WITHOUT GOSUB ERROR will occur. GOSUBs and RETURNs may be
nested, so that one routine may GOSUB another, and the first routine's RETURN will
return properly to the program.
SAVE Stores program to tape without name
SAVE "HELLO" Stores on tape with name HELLO
SAVE A$ Stores on tape with name A$
SAVE "HELLO",8 Stores on disk with name HELLO
SAVE "HELLO",1,1 Stores on tape with name HELLO and follows
program with END-OF-TAPE marker
10 X = VAL("123.456") X = 123.456
10 X = VAL("12A13B") X = 12
10 X = VAL("RIU017") X = 0
10 X = VAL("1.56E3") X = 1560
10 X = VAL("-1.23.45.67") X = -1.23
This command essentially performs a LOAD, but
only checks the data in the file against the current BASIC program instead
of storing it in memory. This command is used to check that a file has been
saved correctly, and that the tape or disk is retaining the information properly.
The filename and device options are the same as the LOAD command.
VERIFY Checks the next program on tape
VERIFY "HELLO" Searches for HELLO, checks against memory
VERIFY "HELLO",8 Searches for HELLO on disk, then checks
against memory