EasyManuals Logo

Sinclair ZX81 User Manual

Sinclair ZX81
92 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #18 background imageLoading...
Page #18 background image
Chapter 7 - Strings
One thing the ZX81 can do that pocket calculators cannot is deal with text. Type
PRINT
"HI THERE. I AM YOUR ZX81." (" is shifted P.)
The chilling greeting inside the quotes is called a string
(meaning a string of characters), & can contain
any characters you like except the string quote,". (But you can use the so-called quote image, "" (shifted
Q), & this will be printed as " by a
PRINT
statement.)
A common typing error with strings is to miss out one of the quotes - this will give you the marker.
If you are printing numbers out, you can use these strings to explain what the numbers mean. For
instance, type
LET
EGGS=61
& then
PRINT
"THE PRICE OF EGGS IS ";EGGS;" NEW PENCE A DOZEN."
(Don't worry about this going over the end of the line.)
This statement displays three things (
PRINT
items), namely the string "THE PRICE OF EGGS IS ", the
number 61 (the value of the variable EGGS), & then the string " NEW PENCE A DOZEN." In fact you can
PRINT any number of items you like, & any mixture of strings & numbers (or expressions), note how the
spaces in a string are just as much part of it as the letters. They are not ignored even at the end.
There are lots of things you can do with strings.
1. You can assign them to variables. However, the name of the variable must be special to show that its
value is a string & not a number: it must be a single letter followed by $ (shifted U). For instance, type
LET
A$="DOUBLE GLOUCESTER"
&
PRINT
A$
2. You can add them together. This is often called concatenation, meaning 'chaining together', & that is
exactly what it does. Try
PRINT
"GAMMO" + "N RASHERS"
You cannot subtract, multiply or divide strings, or raise them to powers.
3. You can apply some functions to strings to get numbers, & vice versa.
STR
$ This is applied to a number, & the result is what would appear on the screen if the number were
displayed by a
PRINT
statement. For instance
STR$
3.5 = "3.5".
4. Just as for numbers, you can combine these to make string expressions, like
V
AL
(
STR$
LEN
"123456"+"-4")
LEN
This is applied to a string, & the result is its length. For instane
LEN
"CHEESE" = 6.
VAL
This applied to a string, & the result is what that string gives when evaluated as an arithmetic
expression. For instance (if A = 9),
VAL
"1/2+
SQR
A" = 3.5. If the string to which
VAL
is applied
contains variables, then two rules must be obeyed.
(i) If the
VAL
function is part of a larger expression, it must be the first item; e.g. 10
LET
X = 7+
VAL
"Y" must be changed to 10
LET
X =
VAL
"Y" +7.
(ii)
VAL
can only appear in the first coordinate of a
PRINT AT
,
PLOT
or
UNPLOT
statement (see
Chapter 17 and 18) e.g. 10
PLOT
5,
VAL
"X" must be changed to
10
LET
Y =
VAL
"X"
15
PLOT
5, Y

Other manuals for Sinclair ZX81

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair ZX81 and is the answer not in the manual?

Sinclair ZX81 Specifications

General IconGeneral
ProcessorZilog Z80A
Processor Speed3.25 MHz
ROM8 KB
InputMembrane keyboard
StorageCassette tape
Power Supply9V DC
Dimensions167 mm x 40 mm x 175 mm
Release Year1981
ManufacturerSinclair Research
Weight350 g
Operating SystemSinclair BASIC
RAM1 KB
PortsTV out, expansion port
DisplayTelevision (RF modulator output)

Related product manuals