# Chapter 10 – Spectrum Hints and Tips (Error-trapping of entries)

Error-trapping of entries
Line renumbering
The ZX printer, Looking after your LLISTings.

Every programmer acquires some working knowledge of the strengths and foibles of the computer system he uses and I have done this with the Spectrum. Because of computing’s very nature, some of these discoveries tend to be repeated for many different people, so apologies to all who have read some of mine elsewhere or have found them out for themselves.

## Error-trapping of entries

Generally any extensive error-trapping is omitted from this book for the sake of brevity. The following routines are offered as guidance — I leave it up to you to decide which part of your program(s) to place them in. Don’t forget to renumber the lines.

1) Protecting numeric iNPUTs within upper and lower limits for DATE and TIME
100 INPUT “month no”, month
110 IF INT month month OR month 12 THEN
GOTO 100
120 INPUT “day no”, day
130 IF INT day day OR day 31 THEN GOTO 120
140 INPUT ”hour (0 to 23)”, hour
150 IF INT hour hour OR hour 23 THEN GOTO 140
160 INPUT “minute (0 to 59)”, min
170 IF INT min min OR min 59 THEN GOTO 160
180 REM program continues INPUTs complete

The following routine is much superior in rejecting any INPUTs that are not composed entirely in numbers (Line 520) and within limits (Line 550).

2) Protecting INPUT to numeric only within upper and lower limits for DATE and TIME
200 LET a\$ = “Year”: LET a = 2000: LET b = 1834: GOSUB 500 : LET y = c
210 LET a\$= “Month”: LET a = 12: LET b= 1: GOSUB 500 : LET m = c
220 LET a\$ = “Day”: LET a = 31: GOSUB 500 : LET d = c
230 LET a\$ = “Hour”: LET a = 23: LET b = 0: GOSUB 500 : LET h = c
240 LET a\$ = “Minute”: LET a = 59: GOSUB 500 : LET mi = c
250 LET a\$ = “Second”: GOSUB 500 : LET s = c
260 REM program continues INPUTs complete 270 ………
500 INPUT (a\$;”(“;b;” to “;a;”)”;), LINE b\$ 510 FOR x = 1 to LEN b\$
520 IF CODE b\$(x) 57 THEN GOTO 600
530 NEXT x
540 LET c = VAL b\$
550 IF c> a OR c< b THEN GOTO 600
560 RETURN : REM INPUT checked OK
600 PRINT # 0 ; FLASH 1 ; “Entry error”: PAUSE 100: GOTO 500

Note: The values of a and b in Line 200 may be for any selected years. Line 500 appears on the screen (using the Year INPUT as an example) as:

Year (1834 to 2000)