Commodore VIC-20 User Manual page 117

Hide thumbs Also See for VIC-20:
Table of Contents

Advertisement

Chapter 3: Programming the VIC 20 Computer
103
The program shown above is not well written. A %(1) can be eliminated,
and N$ need not be an array variable. Can you rewrite the program using N$
and removing A%(I) entirely?
QUOTES IN STRINGS
Although most BASIC programs will not need to print quotation
marks, there are some that do, such as "electronic typewriters" or other
programs that deal with words rather than numbers.
Since quotation marks indicate the beginning and end of strings, you
cannot put them in the middle of a string. You can, however, put a quotation
mark into a string or a PRINT statement using the BASIC function CHR$.
CHR$ acts like an array of all the possible characters. You supply a
subscript, and CHR$ returns the character corresponding to that number.
The values of the subscripts and the characters they produce are listed in
Appendix E. The value for a quotation mark is 34. Using CHR$, you can
print a quotation mark with a statement such as
100 PRINTCHR'(34);"THIS IS DISPLAYED IN QUOTES";CHR'(34)
If you PRINT a string containing control characters, such as
CRSR UP
or
HOME,
you must take an additional step. In Chapter 2 we described the
quote mode. In quote mode, cursor movement keys are translated into
special characters so they can be stored in strings. This allows your program
to perform these functions while it is running.
"Quote mode" also applies to output. To allow you to LIST programs
containing these control characters, the portion of BASIC that puts
information on the display "watches" for quotes. When it finds a quotation
mark, it goes into quote mode and displays control characters in the
reversed form you see when typing them into a program. This can do
unpleasant things to a carefully planned display.
You can escape from quote mode while printing just as you do when
typing in a program: with a second quotation mark or a
RETURN.
Since
programs that print quotation marks usually print them in pairs, you will
seldom see a problem. If your program must print only one, you can use
CHR$ to delete the first one, and then print another to leave quote mode.
100 PR I HTCHR$( 34) i CHR.( 20) ; CHR. (34) ; " IIRV S QUOTED STR I NG!" ; CHR. (34)
CHR$(20) deletes the first quotation mark. Only the second one will appear
on the screen.

Advertisement

Table of Contents
loading

Table of Contents