Radio Shack TRS-80 Model 100 Basic Manual page 69

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

Advertisement

Line 28 The string assigned to HH$ is converted to a numerical value by the VAL
function. This numerical value is assigned to the numeric variable HH. Using the
previous example, HH would have the number 13 assigned to it. Without the VAL
function, it would not be possible to make this assignment.
Line 38 This statement determines whether it is AM or PM and assigns an appropriate
string value to A$. The value stored in HH is compared to the numeric constant 12.
Only a numeric variable can be used in this way. The use of HH$ would have
produced an error and it was for this reason that the string stored in HH$ was changed
to a numeric constant and assigned to the numeric variable HH.
Line
48
The hour value is converted from a 24 hour format to a 12 hour format. For
example, hour 13 would be converted correctly to 1 (PM). In this line, as well in the
previous line, the variable must
be
a numeric variable. The statement:
HH$
=
HH$ - 12
is illegal and would produce an error.
Line 58 This line uses the STR$ function to convert the numeric value stored in HH
back to a string which is then assigned back to the string variable HH$. This will be
concatenated later with another string. In order to do this, a string variable must be
used.
Line 68 This line uses the MID$ function to read the two minutes digits from TIME$
and stores this two-character string in the string variable MM$. Note that the minutes
are the 4th and 5th characters in the string:
13:05:00
MID$(TIME$,4,2) returns two characters starting with the 4th from the left.
Line 78 In this line, the string to be printed is concatenated together from the
variables HH$ (hour), MM$ (minutes), and A$ (AM or PM). A colon is inserted
between the hour and minutes.
Line 88 The message "THE TIME IS" is displayed followed by the time.
Here are some examples of TIME$ and the resulting output of the program:
TIME$
10:15:12
17:08:55
03:18:43
OUTPUT
THE TIME IS 10:15 AM
THE TIME IS 5:08 PM
THE TIME IS 3:18 AM
Note that a leading zero is not printed for the hour. This leading zero is lost when the
VAL function is applied.
The function VAL converts a string constant or variable to a numeric value. The
following examples illustrate this function:
string
123ABBA
2.3CA987
567.4
VAL
123
2.3
567.4
The leftmost characters, up to the first character which cannot be part of a number,
are converted to a number. This function is useful when it is necessary to use a
63

Advertisement

Table of Contents
loading

Table of Contents