Chapter
4:
Advanced
BASIC
Programming
129
The CHR$ function lets you include otherwise unavailable characters such
as
RETURN, INST j
DEL,
and the quote character (") in a
PRINT
statement's
parameters.
You can also use the CHR$ function to check for special characters
such as
RETURN and
INSTjDEL.
Suppose a program must check character
input
at
the keyboard, looking for a RETURN key. You could check for a
RETURN (which has
an
ASCII code of
13)
as follows:
10
GET
Xt:IF
Xt(>CHRt(13)
THEN
10
This test would be impossible if you tried to put RETURN between quotation
marks.
20
IF
X$()III
RETr
N
I"
Impossible
THEN
113
This does
not
work, because pressing the RETURN key following the first set
of
quotation marks automatically moves the cursor to the next line.
20
IF
X$()II
),...
--
Press RETURN key
1-,----'-
If
you attempt
to
program the INST j
DEL
or
the RETURN key, you will
encounter some surprising results.
The
INSERT key
is
programmable. Inside the quotation marks
of
a
PRINT
statement, it displays as II.
If
you try to program the DELETE key in a
PRINT
statement you will
merely erase the previous.character, unless the
DELETE key occurs within a
sequence
of
inserted characters.
The
DELETE key may be entered following
an
INSERT,
but
doing
so
is
not very useful. The only common use
of
this feature
is
in concealing
program lines during a listing (hiding answers for a test, for instance).
Hidden
data
can be easily rediscovered in several ways, however, so using
DELETE characters within program lines
is
not advisable.
The
RETURN character in a
PRINT
statement will immediately move
the cursor out
of
the statement and to the next line.