Commodore 2001-8 User Manual page 43

Table of Contents

Advertisement

Try the following program to develop a feeling for sequences and matching functions:
10 INPUT A$
20 INPUT B$
30 IF A$=B$ THEN? "A$=B$" GOTO 10
40 IF A$ <$B THEN? "A$ <B$" GOTO 10
50 PRINT "A$ >B$": GOTO 10
NUMBERS AND ASCII CODES
Two complementary pairs of operations on strings and numbers allow us to put unconventional things
into character strings.
STR$
STR$ is a function of one argument. It returns a string that is the character representation of the
numeric expression:
10X=3.1
20 ?STR$ (X)
RUN
3.1
READY
Positive numbers are preceded by a blank in the STR$ equivalent. Negative numbers have a sign in the
corresponding position.
VAL
VAL is the complement of STR$.1t converts a string to a number which may be used for computations. If
the first
non-blank character of the string is not numeric, then the value of the function is zero.
?VAL("Z")
o
READY
On the other hand, VAL will convert as many digits as it can up to an invalid character.
?VAL ("3.14 AB")
3.14
VAL is an excellent function to use with INPUT since it can prevent an inexperienced user from causing a
REDO from START.
CHR$
We have shown that strings may be assigned printable ASCII characters through either literals or direct
INPUT, but some devices require control characters which cannot be produced by normal means. For
example,
a PET
printer uses shifted carriage return as a specialterminator to indicate a carriage
return with no tine feed when it performs overprinting. CHR$ allows you to specify such control
characters by giving the ASCII code number. CHR$ is a function to convert a number into internal
ASCII representation. The value of the argument must be
O=X< =255.
10 A$ = CHR$(65)
+
CHR$(66)
20 PRINT A$
RUN
AB
READY.
In the above examples, 65 is the ASCII code for "A" and 66 is a "B". We converted the codes to characters
before concatenating them and printing them out.
39

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents