User-Friendly?

See all articles from T-S Horizons n2
Author(s): Bill Johnson
Publication: T-S Horizons
Pub Details: T-S Horizons n2 (Issue 2)
Date: December 1983
Pages: 14

(Editor’s Note: This column is intended to present tips on clear, concise, “user-friendly” programming.)

One of the simplest programming tricks that can be utilized on the TS 1000/ZX-81 to make your programs “user-friendly” involves a BASIC statement that is a powerful one yet poorly defined and never thoroughly explained in the manual. It is the INKEY$ statement, and I doubt whether most ZX-81 owners have used it outside of game programming, if at all. The statement, when encountered in a program, scans the keyboard momentarily to see if any keys have been depressed. If so, the key is stored in the proscribed variable and if not, the variable remains unchanged. At any rate, the scan does not wait either for a response, or the ENTER key, as the INPUT statement does.

In trying to write programs that are user-friendly, the INKEY$ statement can be used in two ways; first to eliminate some unnecessary keystrokes, and secondly to screen out accidental entries. This method is particularly appropriate when the number of keystrokes can be cut down to one, such as yes or no response (“Y” or “N”) or a single symbol input. The way to make it work is to get the computer to continue scanning the keyboard until a particular key is depressed. The following example illustrates a yes/no input, with the program continuing if yes, branching to line 1000 if no, and ignoring all other inputs.

  10 REM "INPUT ROUTINE"
20 LET I$ = INKEY$
30 IF I$ = "N" THEN GOTO 1000
40 IF I$<> "Y" THEN GOTO 20
50 PRINT "YES"
60 STOP
1000 PRINT "NO"
1010 STOP

As you can see, the program will continue to loop through lines 20, 30 and 40 until one of the two required keys is depressed. With a little imagination, you can modify the program to accept a series of single-keystroke entries.


ERROR CODES – November issue.

Page 14, column 2, “Patriotic Program” Should read “Line 10: 25 grey squares.” “Line 20: 25 squares – gray on top, white on bottom.”

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.