' DIARY.BAS
' This program maintains a computer diary in a sequential file
'   named DIARY.TXT.

CLS

OPEN "DIARY.TXT" FOR APPEND AS #1   ' open file in append mode

PRINT "Enter your secret thoughts for today; type END to quit."
PRINT

PRINT #1, TIME$; "  "; DATE$        ' write time and date to file
PRINT #1,                           ' write blank line to file

DO WHILE (UCASE$(line$) <> "END")   ' until user types "END",
    LINE INPUT line$                '   get lines of text
    IF (line$ <> "END") THEN PRINT #1, line$
LOOP                                '   and write them to the file

PRINT #1,                           ' write blank line to file
CLOSE #1                            ' close file

PRINT                               ' find out if user wants a printout
INPUT "Would you like to print out your entire diary (Y,N)?  ", reply$

IF (UCASE$(reply$) = "Y") THEN        ' if yes,
    OPEN "DIARY.TXT" FOR INPUT AS #1  '   open file for input
   
    LPRINT STRING$(33, "-");        ' print a header at top of page
    LPRINT " My Diary ";
    LPRINT STRING$(33, "-")
    LPRINT                          '   and a blank line

    DO WHILE (NOT EOF(1))           ' until end of file is reached,
       LINE INPUT #1, line$         '   read lines from file
       LPRINT line$                 '   and send them to printer
    LOOP

    CLOSE #1                        ' close file

    LPRINT CHR$(12)                 ' send formfeed character

    PRINT                           ' display message indicating diary
    PRINT "Diary sent to printer"   '   contents have been sent to
END IF                              '   printer

