Classic Computer Magazine Archive COMPUTE! ISSUE 67 / DECEMBER 1985 / PAGE 65

MEMO Diary

Jim Butterfield, Associate Editor

Keep track of important dates, holidays, and personal events with this simple, easy to use BASIC program. It was originally written for Commodore computers (with at least 8K RAM and a tape or disk drive), and modifications are included for the Atari 400/800, XL, and and XE (with at least 16K RAM for tape or 24K RAM for disk); Apple II series (disk only DOS 3.3 or Pro DOS); IBM PC and Enhanced Model PCjr (disk only); and TI-99/4A with Extended BASIC (disk or tape).

"Memo Diary" helps you record and recall birthdays, holidays, appointments, or any other event worth remembering. The program maintains a data file with as many as 100 events whose dates can range from tomorrow to one year in the future. You can record two different types of dates: temporary, one-time events such as appointments which have no importance once they have passed; and permanent, recurring events such as birth days and anniversaries. By routinely running Memo Diary each time you use your computer, you'll no longer have to worry about forgetting to mail a birthday card to a relative or finding an anniversary gift for a spouse.

The program always shows the correct day of the week when you enter a date, and you need to enter the year only once—the very first time you run the program. After that (for the next 99 years, anyway) Memo Diary keeps track of the year for you. Each time you run the program, it automatically shows all due and overdue events on the screen or printer, and erases onetime events from the calendar after they're displayed.

You can enter temporary or recurring new events and erase existing events whenever you wish. You can also examine all events from the current date forward, or search the entire calendar for events matching a given starting pattern. Finally, Memo Diary saves your calendar either on disk or tape.

Typing The Program

We've listed Memo Diary in the form of one main program that contains common routines (Program 1), followed by line changes for each different computer. No matter which computer you're using, you'll need to type in Program 1 plus the modifications for your machine. However, before typing anything, cross out every line in Program 1 that has the same line number as a line in the listing for your specific computer. The idea is to eliminate duplicate lines from the main program; they're replaced by lines from the version for your computer. For example, if you're using an Atari, you would cross out line 150 in Program 1, because there's already a line 150 in the Atari listing (Program 3).

After crossing out duplicate lines in Program 1, type in the listing for your computer. Once that's done, type in every line of the Program 1 that's not crossed out. Be sure to save a copy of the program and read the instructions before running it.

The first time you run Memo Diary is special. Do not start the program by entering RUN. For every version except Atari you should type RUN 100 and press RETURN (or ENTER on the TI and IBM). Atari users should type CLR: GOTO 100 and press RETURN. If you don't do this, the program will not work correctly. When you start the program at line 100, Memo Diary lets you enter the correct year without looking for a previous file of events. Thereafter, start the program with RUN in the usual way.

On the first run you'll probably want to enter fixed holidays such as New Year's Day as well as birthdays and anniversaries. These are permanent events that you won't need to enter year after year. A holiday like Thanksgiving should be entered as a one-time event since it falls on a different date each year.

When Memo Diary asks you to enter today's date, you can type in the name of the month (such as OCTOBER) or its number (such as 10). In either case, be careful to enter it correctly. Memo Diary lets you enter any day of the month from 1 to 31, so it won't mind if you specify the date as February 30. Mistakes like these may confuse the calendar file. For instance, if you use the program on July 4 and the next day mistakenly give the date as June 5, the computer thinks you've let almost a whole year go by. To warn you of this, Memo Diary displays HAPPY NEW YEAR. If you see this message when a new year hasn't arrived, stop the program and start over, entering the correct date.

A Memory Jogger

Except for the very first run, Memo Diary always begins by reporting all due and overdue events ("You just missed your anniversary"). Take careful note of these events, since they'll soon be erased from the calendar (if they're temporary events) or moved ahead to next year (if they're permanent). To help jog your memory, Memo Diary also lets you make a copy of the list of events on your printer.

After disposing of due and overdue events, Memo Diary displays five options: You can see future events, add a new event, cancel an event, search for an event, or quit the program. You'll ordinarily want to look ahead to see what's coming in the next week or two. To do this, choose Option 1 (see future events) and supply an appropriate future date when requested. If you enter the current date when looking at future events, Memo Diary assumes you mean the same date next year and gives you everything on file.

When you want to make a new entry, select Option 2 (add new event). First Memo Diary asks whether the new event is one-time or permanent. Then it lets you enter the date and details. Again, the current date is understood as one year from today (it's assumed you don't need to record an event that's happening the same day).

To cancel an event (Option 3), you must know its date. When an event is entered, you're shown every item scheduled for that date, each with its own code number. To cancel an event, type in its code number when prompted.

Option 4 (search for event) lets you search for an event based on the first few letters of the entry. You may find many events in the course of a search. For instance, if the calendar file contains the events CLUB MEETING, CLUB CONFERENCE, and CLUB ELECTION, searching for CLUB displays all three events. In this case you would not see the entry CANADIAN CLUB, since CLUB is spotted only if it's in the first word of the entry. Thus, if you plan to search for certain keywords (BIRTHDAY, CHURCH, SOFT-BALL, or whatever) keep them at the front of each calendar entry.

After you've finished an option, Memo Diary always returns you to the main menu. Sooner or later you'll be ready to use Option 5 (quit). The program knows when it's time to update the calendar file. If you've erased past and overdue events, added or deleted items, Memo Diary will—with your permission—proceed to update the data file on disk or tape.

The Time Pivot

A program that handles dates can encounter some subtle paradoxes. Does August come before April, or after it? The correct answer is both. Memo Diary could resolve this difficulty by adding a year designation to every event, but that complicates the handling of permanent events, which don't belong to a specific year. This is not a trivial problem: If you schedule a new event for August, the program must decide whether to add the event to the calendar ahead of an existing April event, or after it. Without a year designation, how can anyone tell?

The problem is solved by using a pivot date, usually the same as the current date. If today is July 4, August does indeed come before April. On the other hand, if today is November 11, April comes before August. Since the calendar always looks one year into the future, everything is kept in order.

However, there's one case in which the pivot date can't be the current date. Each time the program begins, it must measure the time lapse since its last use. For example, say that you last used the program on August 20, 1985 and next use it on September 4, 1985. On the first run (August 20) Memo Diary uses August 20 as the pivot. That way an event dated September 1 is seen ahead of another item dated in October.

On the second run (September 4) the September 1 event is reported as past due and either erased from the calendar (if it's temporary) or moved ahead to September 1 of next year (if it's permanent). Once this is done, the pivot date moves forward to September 4, meaning that a September 1 event now belongs after an item dated in October. Don't worry if this sounds confusing: It works out more simply in practice than in theory.

The day of the week is worked out with a simple formula. If you haven't seen it before, here's a hint on how it works. The calendar is modified to make March 1 the first day of the "adjusted year." This way, leap year with its extra February 29 date doesn't break up the sequence of days: The extra leap day just gets pasted onto the year's end. Though the math is a bit convoluted, you may find it interesting to trace the logic of this routine (it starts at line 2150).

Expanding The Calendar

Memo Diary can keep track of a maximum of 100 events. In practice it's wise to limit the number to 80 or 90 to leave room for permanent events that move automatically from the front to the back of the list. If you need more than 100 events, change the L$ value in the DIM statement. Line 150 contains the value L$(100). You can increase the 100 to whatever number you like, but don't get carried away. Since Memo Diary (except the Atari version) uses string arrays, a very large value may cause garbage collection delays. There's no particular limit to the number of events allowed for a particular date.

Program Notes

Let's take a look at the program's major features. Line 90 prepares Memo Diary to read a file. The variable F is a Boolean (logical) variable that's defined as true here, to let you read the calendar file on a normal run. When you enter at line 100 on the first run, F is false (like every other undefined variable) and no file is read.

DATA statements in lines 110–140 hold the names of the months of the year and days of the week; the names are read into the arrays M$ and W$. Line 150 dimensions the L$ array for 100 items. Lines 230–250 call for a reading of the calendar file if appropriate. This is done in the subroutine at line 3010. When Memo Diary reads this file, it detects and reports the last date the file was used. Line 260 asks for today's date; the subroutine at line 1670 asks for and accepts the date.

Now it's time to search for due and overdue events. Using the previous date as a pivot, the subroutine at line 1960 scans for all events up to today's date. The program reports these events, erases them, or moves them ahead as needed, and proceeds to the main menu. Line 680 begins a main activity loop: It prompts with the menu, asks for a choice, then goes to the appropriate subroutine. Line 850 lets you see future events. Since the pivot date is now today, the program scans to the requested future date to see how many events fall into the today-to-future-date range.

Line 940 lets you add a new event. After asking ANNUAL OR ONE-TIME? the program requests the event's date and then asks for details. After adding a year designation to the date of one-time events, the new event is inserted into the proper sequence. Line 1210 lets you cancel an event. Memo Diary asks for a date and then lists all events that match that date. At line 1350, the program asks which event to delete. Note that the number you supply must be in the correct range.

Line 1450 begins the search-for-an-event routine. After it receives a search string (P$), the program looks for a match. When it scans through the calendar, it must look in different places depending on whether the event is one-time or permanent. That's because one­time events carry a year designation, making their dates three characters longer.

A Horrible Mistake?

Line 1570 handles the quit option; the flag F9 registers activity. If you haven't changed any of the data, there's no need to update the calendar file. Before scratching the old file and writing the new one, the program asks whether you're ready. That way, if you made some horrible mistake, you can cancel the file update.

The main loop ends at line 1580 and is followed by several subroutines. The routine starting at line 1590 writes a new calendar file when appropriate, and line 1670 begins the date input routine. The date is formed into a string (D8$) to allow for easy searches or entry. The subroutine at line 1930 reads the calendar file. The first item in the file is always the most recent date of use; the remaining data is events.

The subroutine at line 1960 scans all events to see which have dates between the pivot date (D9$)

and a second date (D8$). There are three dates involved: event, pivot, and the second date, which makes the comparison a bit messy. Boolean variables keep everything in order. Eventually, the variable F0 indicates the date is in range, and the variable L0 indicates when the last event is found within the date range.

The routine starting at line 4020 displays the information, on the printer if desired. (TI users should change line 4070 to match their printer configuration.) The date is given complete with the day of the week, and events falling on the same day are grouped together. The weekday calculation begins at line 2150. The weekday variable, W, ranges from 0 to 6, so 0 means Sunday. As written, this routine is good for years ranging from 85 (1985) to 84 (2084). If you want to plan more than 99 years in advance, you'll need to modify the routine.