10 REM APPOINTMENT CALENDAR
20 REM LAST UPDATED 10-MAY-81
30 REM ***
40 DIM A0$(41,7) : REM APPOINTMENT STRINGS 42 SQUARES BY 8 APTS
50 DIM A0(41) :REM APPOINT INDEXES
60 DIM M0$(12): REM MONTH NAMES
70 DIM M0(12) : REM MONTHS LENGTHS
80 DIM D0$(7) : REM DAY NAMES
90 REM ***
100 PRINT :PRINT CHR$(27);"E":REM CLEAR THE TERMINAL SCREEN
110 PRINT TAB(20) "APPOINTMENT CALENDAR GENERATOR (VER 2.01)"
112 PRINT TAB(20) "VERSION FOR USE WITH LEGAL PRINTWHEELS"
120 PRINT TAB(10) "MODIFIED FOR CP/M AND UPDATED FOR MBASIC BY BARRY N. TILDS"
130 PRINT:PRINT
132 PRINT "I NEED SOME INFORMATION ON THE PRINTER SETTINGS TO KEEP THINGS IN ORDER:"
140 PRINT :PRINT
150 REM READ MONTH NAMES AND LENGTHS
160 FOR I=1 TO 12: READ M0$(I),M0(I):NEXT I
170 DATA "JANUARY",31,"FEBRUARY",28,"MARCH",31
180 DATA "APRIL",30,"MAY",31,"JUNE",30
190 DATA "JULY",31,"AUGUST",31,"SEPTEMBER",30
200 DATA "OCTOBER",31,"NOVEMBER",30,"DECEMBER",31
210 REM DEFAULT OUTPUT DEVICE AND APT. FILE
220 F2$="CALENDAR.APT"
230 'V$="|" :REM VERTICAL BAR ... MAY WANT TO CHANGE FOR DIFFERENT PRINTERS
235 V$ = CHR$(27) + "Y" : REM VERTICAL BAR FOR LEGAL PRINTWHEELS
240 B$="                    ":REM BLANK STRING
250 H$=" SU MO TU WE TH FR SA "
260 REM READ NAMES OF DAYS
270 FOR I=1 TO 7:READ D0$(I):NEXT I
280 DATA "SUNDAY","MONDAY","TUESDAY","WEDNESDAY"
290 DATA "THURSDAY","FRIDAY","SATURDAY"
300 GOSUB 530: REM INITIALIZE
310 REM DO WHILE MORE MONTHS TO PROCESS
320 GOSUB 1190 : REM GET APPT FILE NAME
330 GOSUB 690:REM GET MONTH,YEAR,#COPIES,ETC
340 LINE INPUT "POSITION PAPER. HIT RETURN WHEN READY";A$
350 REM DO NUMBER OF CONSECUTIVE MONTHS
360 FOR N1=1 TO N8+1
370 GOSUB 840 : REM PROCESS APPOINTMENT FILE
380 REM DO WHILE MORE COPIES
390 FOR N=1 TO N9
400 GOSUB 1270:REM PROCESS CALENDAR HEADER
410 GOSUB 1680:REM PROCESS CALENDAR BODY
420 NEXT N
430 REM NEXT CONSEQ MONTH
440 M0=M0+1
450 IF M0>12 THEN M0=1: Y0=Y0+1
460 NEXT N1
470 LINE INPUT "ANY MORE MONTHS?  ";Y$
480 Y$=LEFT$(Y$,1)
490 IF Y$="Y" THEN 310
500 IF Y$="N" THEN SYSTEM
510 PRINT "ANSWER YES OR NO. ";:GOTO 470
520 REM ***
530 REM *** INITIALIZE
540 REM ***
550 INPUT "LINES PER PAGE?  ";L0
560 IF L0<50 THEN PRINT "HUH? ENTER ";:GOTO 550
570 INPUT "COLUMNS PER LINE?  ";C0
580 IF C0<80 THEN PRINT "HUH? ENTER ";:GOTO 570
590 REM COMPUTE MAX APTS PER BOX AND LINES TO NEXT PAGE
600 A9=INT((L0-20)/6)
610 IF A9>8 THEN A9=8
620 L1=L0-A9*6-17
630 REM COMPUTE MAX WIDTH OF APT ENTRY
640 W9=INT((C0-8)/7)
650 REM ADJUST NUMBER OF COLUMNS
660 C0=(W9+1)*7+1
670 RETURN 
680 REM ***
690 REM *** GET MONTH,YEAR, NUMBER OF COPIES ETC
700 REM ***
710 LINE INPUT "NAME OF MONTH?  ";M9$:M9$=LEFT$(M9$,3)
720 FOR M0=1 TO 12
730 IF M9$=LEFT$(M0$(M0),3) THEN 760
740 NEXT M0
750 PRINT "HUH? ENTER ";:GOTO 710
760 INPUT "YEAR (EG. 1980)?  ";Y0
770 IF Y0<1582 THEN PRINT "HUH? ENTER ";:GOTO 760
780 INPUT "NUMBER OF CONSECUTIVE MONTHS?  ";N8
790 PRINT :PRINT "EACH CALENDAR TAKES SEVERAL MINUTES TO COMPUTE"
800 PRINT "...... BE PATIENT":PRINT 
810 INPUT "NUMBER OF COPIES?  ";N9
820 RETURN 
830 REM ***
840 REM *** PROCESS APOINTMENT FILE
850 REM ***
860 Y=Y0:M=M0:GOSUB 1960 : REM GET FIRST DAY INDEX
870 I0=D9 : REM SAVE INDEX FOR LATER
880 D0=D8 : REM # DAYS IN MONTH
890 REM INITIALIZE APPT. ARRAYS
900 FOR I=0 TO 41
910 A0(I)=A9-1
920 FOR J=0 TO A9-1
930 A0$(I,J)=LEFT$(B$,W9)
940 NEXT J
950 NEXT I
960 OPEN "I",2,F2$
970 LINE INPUT #2,T$:REM READ TITLE LINE
980 REM DO WHILE MORE APPT. RECORDS
990 INPUT #2,M,D,Y,A$: REM GET MONTH,DAY,YEAR,APPT STRING OR END-SENT
1000 IF M=99 THEN 1090
1010 IF Y<>Y0 THEN 990
1020 IF M<> M0 THEN 990
1030 IF D<1 OR D>D0 THEN 990
1040 D=D9+D-1 : REM ADJUST FOR DAY OF WEEK FOR 1ST DAY.
1050 IF A0(D)<0 THEN 990 : REM DAY FULL
1060 A0$(D,A0(D))=LEFT$(A$+B$,W9) : REM SAVE APPT. STRING IN BOX
1070 A0(D)=A0(D)-1
1080 GOTO 990
1090 CLOSE #2
1100 REM FILL IN DAY NUMBERS
1110 D=1
1120 FOR I=D9 TO D0+D9-1
1130 A$=STR$(D)
1140 A0$(I,0)=LEFT$(A0$(I,0),LEN(A0$(I,0))-LEN(A$))+A$
1150 D=D+1
1160 NEXT I
1170 RETURN 
1180 REM ***
1190 REM ***
1200 REM *** GET APPT FILE NAME
1210 REM ***
1220 PRINT "APPOINTMENT FILE NAME <";F2$;">";
1230 LINE INPUT F9$
1240 IF F9$<>"" THEN F2$=F9$
1250 RETURN 
1260 REM ***
1270 REM *** PROCESS CALENDAR HEADING
1280 REM ***
1290 REM PREVIOUS AND NEXT MONTH
1300 IF T$="" THEN LPRINT :GOTO 1320
1310 M1=M0-1:Y1=Y0
1320 IF M1<1 THEN M1=12:Y1=Y1-1
1330 M2=M0+1:Y2=Y0
1340 IF M2>12 THEN M2=1:Y2=Y2+1
1350 Y=Y1:M=M1:GOSUB 1960:D1=-D9+1:S1=D8
1360 Y=Y2:M=M2:GOSUB 1960:D2=-D9+1:S2=D8
1370 H1$=M0$(M1)+STR$(Y1)
1380 H2$=M0$(M2)+STR$(Y2)
1390 LPRINT TAB((22-LEN(H1$))/2);H1$;
1400 LPRINT TAB(C0-21+(22-LEN(H2$))/2);H2$
1410 T$=LEFT$(T$,C0-42)
1420 LPRINT H$;SPC((C0-42-LEN(T$))/2);T$;TAB(C0-21);H$
1430 REM PRINT DAYS OF PREV AND NEX MONTH
1440 GOSUB 1540:GOSUB 1570:LPRINT 
1450 GOSUB 1540:GOSUB 1570:LPRINT 
1460 GOSUB 1540
1470 LPRINT SPC((C0-42-LEN(M0$(M0))-6)/2);M0$(M0);Y0;
1480 GOSUB 1570:LPRINT 
1490 GOSUB 1540:GOSUB 1570:LPRINT 
1500 GOSUB 1540:GOSUB 1570:LPRINT 
1510 GOSUB 1540
1520 IF D1>S1 AND D2>S2 THEN LPRINT :RETURN 
1530 GOSUB 1570:LPRINT :RETURN 
1540 REM PRINT PREV MONTH DAYS
1550 D=D1:D1=D1+7:S=S1
1560 GOTO 1600
1570 REM PRINT NEXT MONTH DAYS
1580 D=D2:D2=D2+7:S=S2
1590 LPRINT TAB(C0-21);
1600 FOR I=1 TO 7
1610 IF D<1 OR D>S THEN A$="   ":GOTO 1630
1620 A$=RIGHT$(" "+STR$(D),3)
1630 D=D+1
1640 LPRINT A$;
1650 NEXT I
1660 RETURN 
1670 REM ***
1680 REM *** PROCESS BODY OF CALENDAR
1690 REM ***
1700 GOSUB 1920:REM DASHES
1710 FOR I=1 TO 7
1720 J1=INT((W9-LEN(D0$(I)))/2) : J2=W9-J1-LEN(D0$(I))
1730 LPRINT V$;SPC(J1);D0$(I);SPC(J2);
1740 NEXT I
1750 LPRINT V$
1760 GO14(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(214(6
 V$;
1830 FOR I3=0 TO 6 : REM 7 BOXES ACROSS
1840 LPRINT A0$(D+I3,I2);V$;
1850 NEXT I3 : LPRINT 
1860 NEXT I2
1870 GOSUB 1920 : D=D+7
1880 NEXT I1
1890 REM SPACE TO NEXT PAGE
1900 FOR I=1 TO L1 : LPRINT :NEXT I
1910 RETURN 
1920 REM *** PRINT LINE OF DASHES
1930 FOR I=1 TO C0:LPRINT "-";:NEXT I
1940 LPRINT :RETURN 
1950 REM ***
1960 REM *** GET FIRST DAY INDEX (DAY OF WEEK OF 1ST OF MONTH)
1970 REM ***
1980 REM EQUATIONS TAKEN FORM 'DAYOFWK' BY JIM BROCK
1990 IF M>2 THEN GOTO 2020
2000 D9=365*Y+1+31*(M-1)+INT((Y-1)/4)-INT(.75*INT(((Y-1)/100+1)))
2010 GOTO 2030
2020 D9=365*Y+1+31*(M-1)-INT(.4*M+2.3)+INT(Y/4)-INT(.75*(INT(Y/100)+1))
2030 D9=INT(D9-INT(D9/7)*7)
2040 D9=D9-1: IF D9<0 THEN D9=6
2050 REM COMPUTE DAYS IN MONTH
2060 D8=M0(M)
2070 IF M<>2 THEN RETURN 
2080 IF INT(Y/4)*4 =Y THEN D8=D8+1 :REM LEAP YEAR IN FEB.
2090 RETURN 
UH? ENTER ";:GOTO 710
760 INPUT