First Steps

Les Ellingham

 

Issue 5

Sep/Oct 83

Next Article >>

<< Prev Article

 

No-one sent in any suggestions for improving John Dimmer's program in issue 4 and I can therefore only assume that readers of this column are either not advanced enough to attempt changes in programs or else nobody reads the column because it is too basic (pardon the pun). Unless readers really do want a column on hints and tips when first starting and show it by writing in, this may be the last First Steps.

As nobody else was brave enough, I will see if I can find any areas for improvement in John's program. Firstly though let's look at the good points of the program.

Any program should have some sort of introduction to show that something is happening once you hit return. With short programs this may not be too important, but once you get to writing programs which require a lot of initialisation, there may be quite a wait with a blank screen before the user realises that the program is actually running. Not so good. John's program has a title and line 9 is an excellent idea as, whilst the words are not strictly true (i.e. the main program is not actually loading), the user is expecting to wait a short while. Further on, line 75 opens the keyboard for getting characters without pressing RETURN. This can be important for non-computerists, for if they are asked to press a key, why should they think of pressing another key as well? Write your programs with others in mind. Redefining the character set was a brave step in a simple program but is well worth trying. The £ sign produced is perhaps too large though - try using DATA 0, 62, 54, 48, 120, 54, 126, 0.

The main limitation in the program is in actually defining fixed categories within the program code which requires you to actually change the code if you want different categories. There is an advantage in that you can CSAVE the program without learning about printing strings etc. to tape and you do not have to know about string manipulation. There is a better way though of including the categories without resorting to string storage and that is to use READ and DATA. If you also place the figures for each category in an array, changing the categories would require only changes in one or two lines. Take lines 83-90 and try this. Change line 61 to

61 DIM C$(12), W(50), A$(20), J(8) :FOR I= 1 TO 8:J(I)=0:NEXT I

and then replace lines 83-90 with the following

83 RESTORE 90: FOR J=1 TO 8: READ A$: POSITION 2, J+5:? A$: POSITION 27,J+5:? "!"; J(J) :A$="":NEXT J

90 DATA MORTGAGE REPAYMENTS,ENDOWMENT INSURANCE,LOCAL RATES,BANK PERSONAL LOAN,VIDEO HIRE,TV HIRE,

91 DATA HIRE PURCHASE LOAN,MISCELLANEOUS

You will of course need to put the appropriate figures in the array J and this can be done by altering lines 102 to 110. There is an easy way to eliminate all those IF ... THEN statements as follows

102 GET #4,Z:CAT=Z-64

103 ? CHR$(Z);" = !";:INPUT SUM:J(CAT)=SUM

Note that 9 program lines have been reduced to two lines and only three variables are used instead of 9. Note also the introduction of more meaningful variable names which help to make the program more readable and easier to remember. Finally change line 125 to

125 FOR I=1 TO 8:M=M+J(I):NEXT I

Note that there is no error checking in the program so that if you press the wrong key you will get an error.

By using an array like this, it is very easy to add further categories simply by increasing the size of the array.

There you have a few possible changes, but there are many more that could be made. I hope though that these few examples have given you just a bit more insight into programming.

top