Radio Shack TRS-80 Model 100 Basic Manual page 65

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

Displays as
Lines 58 • 68 These DATA statements contain the list of the days of the week.
Lowercase letters must be used for the second and third characters to correctly match
DAY$, which stores the first three characters of each day of the week (an uppercase
and two lowercase letters).
This program uses two string functions, DAY$ and LEFT$. Recall that DAY$ returns
the first three letters of the day of the week.
The function LEFT$(D$,3) returns the first three characters of the string stored in D$.
For example, if D$ has Thursday assigned to it, then
PRINT LEFT$(D$,3)
would display
Thu
The number 3 indicates the number of characters to be returned. Again assuming that
D$ contains Thursday, then
Command
PRINT LEFT$(D$,1)
PRINT LEFT$(D$,2)
PRINT LEFT$(D$,5)
etc.
T
Th
Thurs
LEFT$ is a string function of two arguments, the string (D$) and the number of
characters to be returned. The first argument need not be a string variable, it can also
be a string constant. For example,
PRINT LEFTS( "Model
100" ,3)
would display as:
Mod
When a string constant is used as the argument, it must be enclosed in quotation
marks.
The last character in the name of both functions, LEFT$ and DAY$, is a dollar sign
($) because the quantity returned, in both cases, is a string.
Experiment #2 Centering the
Day
Program DAY is to be changed so that the output will consist of the day of the week,
centered in the line with an equal number of asterisks
(*)
printed on both sides.
Make the following changes:
Retype line 40 as:
1I0 L
=
LEN·( OS)
and
type
four new lines:
5
CLEAR 100
1I1i AS
=
STRINGS(
(1I0 - L)/2,
u*U)
~G
OS
=
AS
+
OS
+
AS
LIB PRINT OS
59

Advertisement

Table of Contents
loading

Table of Contents