' A simple dedicated database program which keeps track of
' newspaper and pamphlet distribution contracts.
' This program is in the public domain. The author accepts no
' liability for anything.
' Written by Matt McLeod (mjmcleod@maria.wustl.edu, c9106225@wombat.newcastle.edu.au)
DECLARE SUB PrintData ()
DECLARE SUB DrawScreen ()
DECLARE SUB DrawLine (row AS INTEGER)
DECLARE SUB GetContract ()
DECLARE SUB LoadData (filename AS STRING)
' Constants for boolean stuff
CONST true = -1, false = 0
' Datatype to hold date info
TYPE DateType
Day AS INTEGER
Month AS INTEGER
Year AS INTEGER
END TYPE
' Datatyoe to hold contract info
TYPE ContractRec
Number AS STRING * 6
DateReceived AS DateType
DatePayed AS DateType
Amount AS SINGLE
END TYPE
' the main storage of data
DIM SHARED Contract(1 TO 1000) AS ContractRec
' a couple of miscellaneous variables
DIM SHARED TotalContracts AS INTEGER
DIM SHARED TopOfScreen AS INTEGER
DIM SHARED Current AS INTEGER
' and now the program...
CLS
INPUT "Filename: "; filename$
IF filename$ <> "" THEN LoadData (filename$)
' if no filename was entered, then no file is loaded.
' now a few initializations...
Done = false
TopOfScreen = 1
Current = 1
Redraw = true
DO
IF Redraw THEN DrawScreen
IF TotalContracts = 0 THEN
GetContract
DrawScreen
END IF
VIEW PRINT 5 TO 23
IF Redraw THEN
PrintData
ELSE
' This bit handles only drawing a single line of data
LOCATE Current - TopOfScreen + 5, 1
COLOR 15
PRINT Contract(Current).Number; TAB(20);
PRINT USING "##/##/##"; Contract(Current).DateReceived.Day; Contract(Current).DateReceived.Month; Contract(Current).DateReceived.Year; TAB(32);
IF Contract(Current).DatePayed.Day <> 0 THEN PRINT USING "##/##/##"; Contract(Current).DatePayed.Day; Contract(Current).DatePayed.Month; Contract(Current).DatePayed.Year;
PRINT TAB(48);
PRINT USING "$$,####.##"; Contract(Current).Amount
IF TopOfScreen > TotalContracts THEN TopOfScreen = 1
GotIt = true
CASE CHR$(0) + CHR$(73) ' and page Up!
TopOfScreen = TopOfScreen - 15
IF TopOfScreen < 1 THEN TopOfScreen = 1
GotIt = true
CASE CHR$(0) + CHR$(59) ' help bit
VIEW PRINT
CLS
OPEN "papers.hlp" FOR INPUT AS 1
DO UNTIL EOF(1)
LINE INPUT #1, a$
PRINT a$
LOOP
DO
LOOP UNTIL INKEY$ = CHR$(13)
CLOSE 1
GotIt = true
CASE CHR$(0) + CHR$(72) ' Up
LOCATE Current - TopOfScreen + 5, 1
COLOR 7
PRINT Contract(Current).Number; TAB(20);
PRINT USING "##/##/##"; Contract(Current).DateReceived.Day; Contract(Current).DateReceived.Month; Contract(Current).DateReceived.Year; TAB(32);
IF Contract(Current).DatePayed.Day <> 0 THEN PRINT USING "##/##/##"; Contract(Current).DatePayed.Day; Contract(Current).DatePayed.Month; Contract(Current).DatePayed.Year;
PRINT TAB(48);
PRINT USING "$$,####.##"; Contract(Current).Amount
Current = Current - 1
IF Current = 0 THEN Current = TotalContracts
GotIt = true
Redraw = false
CASE CHR$(0) + CHR$(80) ' Down
LOCATE Current - TopOfScreen + 5, 1
COLOR 7
PRINT Contract(Current).Number; TAB(20);
PRINT USING "##/##/##"; Contract(Current).DateReceived.Day; Contract(Current).DateReceived.Month; Contract(Current).DateReceived.Year; TAB(32);
IF Contract(Current).DatePayed.Day <> 0 THEN PRINT USING "##/##/##"; Contract(Current).DatePayed.Day; Contract(Current).DatePayed.Month; Contract(Current).DatePayed.Year;
PRINT TAB(48);
PRINT USING "$$,####.##"; Contract(Current).Amount
Current = Current + 1
IF Current > TotalContracts THEN Current = 1
GotIt = true
Redraw = false
END SELECT
IF Current < TopOfScreen THEN
TopOfScreen = Current - 15
IF TopOfScreen < 1 THEN TopOfScreen = 1
Redraw = true
END IF
IF Current > TopOfScreen + 17 THEN
TopOfScreen = TopOfScreen + 15
IF TopOfScreen > TotalContracts THEN TopOfScreen = TotalContracts
Redraw = true
END IF
LOOP UNTIL GotIt
VIEW PRINT
LOOP UNTIL Done
SYSTEM
SUB DrawLine (row AS INTEGER)
' This sub draws a single line along the specified row
LOCATE row, 1
FOR i = 1 TO 80
PRINT CHR$(196);
NEXT
END SUB
SUB DrawScreen
' This sub draws the screen (not including the data) and also calculates
' a few things...
VIEW PRINT
TotalEarnt = 0
TotalPayed = 0
IF TotalContracts <> 0 THEN
FOR i = 1 TO TotalContracts
TotalEarnt = TotalEarnt + Contract(i).Amount
IF Contract(i).DatePayed.Day <> 0 THEN TotalPayed = TotalPayed + Contract(i).Amount