C Regena
Printing
A Schedule Of Events
The first peripheral I got for my TI was a printer. At first I used it mainly for program listings. Later, I discovered that adding a printer significantly increased the possible applications for the computer. All kinds of reports could be generated, lists sorted, and charts and graphs plotted. For some reason, if something was printed using a computer it looked more "official." Of course, a report is really only as good as whatever the programmer or computer user enters, but using your TI and a printer, you can make very impressive reports.
On the other hand, if you don't want something to look computergenerated, you can use a letter quality printer. When the TI-99/4 first came out, only one printer was available for it (remember the TI thermal printer?). Next came a peripheral system that required the RS-232 interface which could be used with several different brands of printers. Now there are many more printers available and several kinds of interfaces or special cables, so there is no one standard way of using a printer. There are also several word processing programs available.
Printing In BASIC
In TI BASIC programming, the most common way to print something is to use the PRINT # statement (pronounced print file), which means print to a file or device. First, use OPEN # (open file) to define the printer for the computer. The manual for the interface or printer you use should have sample OPEN statements for your particular printer. When you're finished printing, use CLOSE # (close file). For example, here's what I need for my TI printer:
100 OPEN #1:"RS232.BA=600"
To print a message, for example:
110 PRINT #1:"HELLO"
Then, when finished, use:
900 CLOSE #1
The critical statement is the OPEN # statement, which must be tailored to your own printer configuration. The PRINT # and CLOSE # statements can be the same for any type of printer.
This month's program illustrates the use of a printer for creating a simple schedule of events or calendar of happenings. This program just gives the basic idea of how you can sort events by date and time. For example, you could use this program to list your activities for the summer. With my large family, I need to keep a written list of what's going on. To customize this program, add your own title and change the printing to fit your needs. The program as is simply lists the dates, times, and events in single spacing, but all kinds of special formats are possible, including a full, graphic calendar.
How It Works
The events are listed in DATA statements. For examples, I have used several events in lines 1240-1480. The last DATA statement should use 9999 for the date. The data for each event consists of the date, the time, and a description of the event. The date is a four-digit string. The first two numbers range from 01 to 12, representing the month. The last two numbers are the day of the month (01-31). The time is also a four-digit string. This is a number expressed as 24-hour time without a colon between the hours and minutes. Thus, 0800 is eight o'clock in the morning, and 1200 is twelve o'clock noon. Eight o'clock in the evening expressed in 24-hour time is 2000. For no specified time, use 0000.
This format helps in the sorting procedure. You may prefer to enter the data in a different way, then let the program convert to numbers for sorting. The numbers are converted to months, days, hours, and minutes during the printing procedure.
Lines 110-120 dimension variables DT$ (date and time) and EVENT$ for 50 events starting with base 1. M$ is dimensioned and will hold the names of the 12 months. Lines 200-240 define these month names in the M$ array.
The variable E is the number of an event. Line 270 READS from the data the date, time, and event. Line 280 checks to see whether all the data has been read. Line 300 increments E; then line 310 makes sure E is less than 51 for the subscript.
Lines 330-640 sort the events by date and time. I call this type of sort "maximum-minimum" because the first pass through the data finds the maximum and minimum items in the array and places them at the end points. Successive passes through the items move the ends inward and place the maximums and minimums at those positions.
Lines 740-1190 print the events in date order. Remember to put your own printer configuration in the OPEN statement in line 760. The variable DT$ is divided back into DATE$ and TIME$. The date is then separated so that a month name is printed with the day. The time is converted to the usual written format of hour:minute, and A.M., NOON, or P.M. is added.
If you don't have a printer, you can simply print the schedule on the screen. To control scrolling, PR is used as a variable to count how many lines have been printed on the screen. When the printing stops, press the space bar to continue the list. At the end of the list, press the space bar to get back to the menu screen.
If you wish to save typing effort, you can receive a copy of this program ("TI Calendar") by sending a blank cassette or disk, a stamped, self-addressed mailer, and $3 to:
C. Regena
P.O. Box 1502
Cedar City, UT 84720
TI Calendar
100 REM CALENDAR
110 OPTION BASE 1
120 DIM DT$(50),EVENT$(50)
130 DIM M$(12)
140 CALL CLEAR
150 PRINT TAB(6);"** CALEND
AR **"
160 PRINT :::"ENTER DATES A
ND EVENTS IN"
170 PRINT :"DATA STATEMENTS
."
180 PRINT ::"YOU MAY PRINT
THE CALENDAR"
190 PRINT ::"ON THE SCREEN
OR PRINTER.":::
200 FOR M=1 TO 12
210 READ M$(M)
220 NEXT M
230 DATA JAN,FEB,MAR,APR,MA
Y,JUN
240 DATA JUL,AUG,SEP,OCT,NO
V,DEC
250 PRINT "...READING DATA.
.."
260 E=1
270 READ DATE$,TIME$,EVENT$
(E)
280 IF DATE$="9999" THEN 32
0
290 DT$(E)=DATE$&TIME$
300 E=E+1
310 IF E<51 THEN 270
320 E=E-1
330 PRINT :"...SORTING..."
340 N=E
350 S=1
360 MN$=DT$(S)
370 IMIN=S
380 MX$=MN$
390 IMAX=S
400 FOR I=S TO N
410 IF DT$(I)<=MX$ THEN 440
420 MX$-DT$(I)
430 IMAX=I
440 IF DT$(I)>=MN$ THEN 470
450 MN$=DT$(I)
460 IMIN=I
470 NEXT I
480 IF IMIN<>N THEN 500
490 IMIN=IMAX
500 AA$=DT$(N)
510 BB$=EVENT$(N)
520 DT$(N)=DT$(IMAX)
530 EVENT$(N)=EVENT$(IMAX)
540 DT$(IMAX)=AA$
550 EVENT$(IMAX)=BB$
560 N=N-1
570 AA$=DT$(S)
580 BB$=EVENT$(S)
590 DTS(S)=DTS(IMIN)
600 EVENT$(S)=EVENT$(IMIN)
610 DT$(IMIN)=AA$
620 EVENT$(IMIN)=BB$
630 S=S+1
640 IF N>S THEN 360
650 PRINT :::"CHOOSE:"
660 PRINT :"1 PRINT ON SCRE
EN"
670 PRINT :"2 PRINT ON PRIN
TER"
680 PRINT :"3 END PROGRAM"
690 CALL KEY(0,K,S)
700 K=K-48
710 IF (K<1)+(K>3)THEN 690
720 CALL CLEAR
730 ON K GOTO 770,760,1490
740 REM PRINTING
750 REM PUT PRINTER CONFIG
URATION HERE
760 OPEN #1:"RS232.BA=600"
770 FOR T=1 TO E
780 DATES=SEG$(DT$(T),1,4)
790 M=VAL(SEG$(DATE$,1,2))
800 MON$=M$(M)
810 DAYS=MON$&" "&SEG$(DATE
$,3,2)
820 TIMES=SEG$(DT$(T),5,4)
830 IF TIME$<>"0000" THEN 8
70
840 TIME$=" "
850 T$=" "
860 GOTO 1000
870 H=VAL(SEG$(TIME$,1,2))
880 IF H>=12 THEN 910
890 T$="A.M."
900 GOTO 970
910 IF H<>12 THEN 950
920 IF SEG$(TIME$,3,2)<>"00
" THEN 960
930 T$="NOON"
940 GOTO 970
950 H=H-12
960 T$="P.M."
970 TIMES=STR$(H)&":"&SEG$(
TIME$,3,2)
980 IF LEN(TIME$)>4 THEN 10
00
990 TIME$=" "&TIME$
1000 TT$=TIME$&" "&T$
1010 IF K=2 THEN 1110
1020 PRINT :DAY$;" ";TT$
1030 PRINT " ";EVENT$(T)
1040 PR=PR+3
1050 IF PR<24 THEN 1120
1060 IF T=E THEN 1120
1070 CALL KEY(0,K,S)
1080 IF S<1 THEN 1070
1090 PR=0
1100 GOTO 1120
1110 PRINT #1:DAY$;" ";TT$
;" ";EVENT$(T)
1120 NEXT T
1130 PR=0
1140 IF K<>2 THEN 1170
1150 CLOSE #1
1160 GOTO 650
1170 CALL KEY(0,K,S)
1180 IF S<1 THEN 1170
1190 GOTO 650
1200 REM DATA FOR EVENTS
1210 REM DATE,TIME,EVENT
1220 REM DATE IS MMDD
1230 REM TIME IS HHMM
1240 DATA 0415,0000,CINDY'S
BIRTHDAY
1250 DATA 0415,1700,MAIL IN
COME TAX
1260 DATA 0509,0000,RICHARD
'S BIRTHDAY
1270 DATA 0510,0000,BOB'S B
IRTHDAY
1280 DATA 0611,0000,CHAN'S
BIRTHDAY
1290 DATA 0304,1200,SUSC VS
BYU BASEBALL
1300 DATA 0305,1200,SUSC VS
BYU BASEBALL
1310 DATA 0314,1300,SUSC VS
UTAH BASEBALL
1320 DATA 0315,1300,SUSC VS
UTAH BASEBALL
1330 DATA 0328,1300,SUSC VS
MESA BASEBALL
1340 DATA 0329,1230,SUSC VS
MESA BASEBALL
1350 DATA 0429,1300,SUSC BA
SEBALL
1360 DATA 0430,1300,SUSC BA
SEBALL
1370 DATA 0314,0715,SKI CLU
B--RICK
1380 DATA 0225,0000,CINDY S
KIING
1390 DATA 0328,1500,CHERY P
ARTY
1400 DATA 0222,1930,SUSC BA
SKETBALL
1410 DATA 0303,2000,SYMPHON
Y
1420 DATA 0330,0000,EASTER
1430 DATA 0526,0000,MEMORIA
L DAY
1440 DATA 0607,0000,COMMENC
EMENT
1450 DATA 0704,0000,INDEPEN
DENCE DAY
1460 DATA 0724,0000,PIONEER
DAY
1470 DATA 0710,1000,SHAKESP
EARE FESTIVAL
1480 DATA 9999,0000,ZZZ
1490 END