HOME MANAGEMENT GRAPHICS
by A.G. Cameron
from ZX Computing Feb/Mar.1986

Glaswegian Mr A.G. Cameron provides a
graphic account of your domestic finances.


This program began as a simple routine which I used to plot
a bar chart of my electricity bills since I moved into my
new house! Gradually it has developed a proper INPUT
routine, a SAVE routine, a facility to list the current
data, and the ability to generate a vertical scale
automatically. With the recent arrival of a new ZX printer,
it has also acquired hardcopy facilities.

There is extensive use of subroutines in the program, as I
am a confirmed 'structured' programmer, and this is the
easiest way to add new code to an old program.

Line 1030 sets up the array to contain your data, and lines
1040 and 1050 prompt for and accept a title for the chart.
Line 1060 calls a subroutine to set up the required vertical
axis scale, based on the maximum value you wish to plot.
These statements are only executed on the initial setting-up
run of the program.

Lines 1070 to 1210 display the main menu screen and call the
appropriate subroutine depending on the user's selection.

The rest of the program consists of the various subroutines
for accepting (1220-1360), correcting (2140-2280) and
listing (1370-1750) data, plotting the barchart (1760-1940),
printing the chart (1950-1990), and saving the program with
its data (2080-2130).


Scale

The subroutine entitled "SCALE DEFINITION" (2330-2480) looks
confusing at first glance. This sets up the vertical axis
scale. The user is prompted for the maximum value he wishes
to plot to (M). Lines 2380-2400 work out a number which,
when multiplied by four, will give a value (N) greater than
or equal to M. The labels for the scale are then worked out
by accumulating N four times. D is the number which, when
divided into the data, will produce a result less than 44,
so that it can be plotted on the ZX81's 64 x 44 grid. Lines
2410 to 2470 store the vertical axis labels for later use by
the plot routine.

The accompanying hierarchical diagram [see HOMEMANG.GIF]
shows the relationships between all the subroutines called
in the program. I find diagrams like these extremely useful
as an aid to understanding the logical structure of a
program.

After typing in the program and RUNning it for the first
time, you will be asked for a title for the chart, then for
the maximum value you wish to plot. When you have responded
to these prompts you will be presented with the main menu.
Enter the number of the option you want, and press
"NEWLINE". Option 2 - Input Data - is a good place to start!

To save the program and data, enter option 5. On reloading,
the program will run automatically, and go straight to the
main menu, missing out the "TITLE" and "SCALE DEFINITION"
steps. If you want to change the scale or the title, you
have to leave the program (option 6), and enter:

GOTO 1040

The Title and Scale Definition screens will be displayed
again, and you can enter new values. Remember that if you
use RUN again, your data will be destroyed as the array
A(24) will be re-initialised. To re-enter the program at the
main menu after exiting for any reason, enter:

GOTO 1070

There are still some enhancements which could easily be
incorporated into this program. For example, how about fully
automatic scaling? All you need is a fairly simple module,
called from the Plot routine, to scan through the data array
to find the highest value, then call a modified version of
the Scale Definition module to set up your axis labels. A
more interesting project would be to replace the existing
Plot module with one which uses block graphics symbols to
plot two values side by side (a 'clustered bar' chart).

Happy (structured) programming.


-- end of file --
