Radio Shack TRS-80 Model 100 Basic Manual page 68

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

Advertisement

Experiment #3 What time is it?
Another useful feature of your Model 100 Computer is the string function TIME$,
which returns the time as a string of the form
hh:mm:ss
For example, if the time is exactly 1:05 PM, then the following command:
PRINT TIME$
would print
13:05:00
The first two digits indicate the hour
(l
PM), the second two digits the minutes; (5
minutes after
1),
and the last two digits the seconds.
The clock is a 24 hour clock, so the hours will range from 00 to 23, with 00
indicating midnight.
Note: The time must be initialized prior to using the TIME$ function. Once set, it will
keep the correct time just like a clock. If you have not already initialized the time,
you may do so by entering the following command:
TIME$
=
"hh:mm:ss"
where hh is the hour, mm the minute, and ss the seconds. The hour is in 24 hour
format, so that 3 PM is hour 15. For example, if the current time is 3:05 PM, type
TIME$ = "15:05:00" (ENTER)
The following program will convert the string returned by TIME$, for example
14:18:00, to the customary format, 2:18 PM.
Clear the previous program from memory with the NEW command and then type the
following program:
10 HH$ = LEFT$(TIME$,2)
20 HH = VAL< HH$)
30 IF HH>= 12 THEN A$
= "
PM" ELSE A$
= "
AM"
40 IF HH > 12 THEN HH
=
HH - 12
50 HH$
=
STR$(HH)
60 MMS
=
MID$(TIME$,4,2)
70 T$ = HH$
+ ":" +
MM$
+
AS
80 PRINT "THE TIME IS"; T$
After the program has been entered, execute it with the RUN command. An example
of the output is
THE TIME IS 1:05 PM
Line
Ht
The first two characters in TIME$ are assigned to the string variable HH$.
These two characters designate the hour. For example, if it is 1:05 PM, then HH$ will
contain the two characters 13. Since LEFT$ returns a string, these two characters form
a string even though they are numerical digits. Thus they cannot be assigned to a
numeric variable.
62

Advertisement

Table of Contents
loading

Table of Contents