Absolutely bombproof input routine. Chris Glenn.
Absolutely Bombproof Input Routine
Like the search for an honest man, the search for a truly user-proof INPUT routine never seems to end. Greg Kielian's attempt (Creative Computing, November 1980) was noble, but erases characters from the INPUT line when the back arrow is used. Susan Luca solved that problem (Creative Computing, May 1981), but her routine was tailored specifically for her own needs.
Absolutely Bombproof Input is constructed for more general applications, and is absolutely positively bombproof (except, alas, for our old nemesis RESET). Any alphanumeric or special character is permitted, including ] (SHIFT-M), but control characters are rejected. The forward and back arrow keys are fully functional and can be used to move anywhere on the INPUT line without affecting characters on the screen. The routine is very fast, so lag time between the keystroke and printing to the screen is insignificant.
Another feature lets the programmer choose the maximum length of the INPUT line and place it anywhere on the screen by assigning variables L, H, and V (Length, Horizontal position, Vertical position) to suit. Should the INPUT length reach the specified maximum while the routine is in use, the cursor simply sits and beeps until a back arrow or RETURN, signifying end of INPUT, is pressed.
The Main Program: Musts And Limits
Lines 0-120 of the listing constitute the trivial main program for this demonstration, but contain significant features which must be included in any main program with which the Absolutely Bombproof Input routine is used.
It is up to the programmer, as in line 20 of the demo, to dimension the two string arrays, C$ and TC$, used by the routine to assemble the INPUT. And the main program must also set values for the aforementioned programmer-controlled L, H, and V variables, as in line 30 of the demo.
Be reasonable; you obviously can't set V = 23 if L = 200; there aren't enough rows left on the screen for all those characters. Nor can you, under any circumstances, set L and H so that their sum is greater than 254 or you will be asking the routine to exceed the maximum string length of Applesoft. Either way, Absolutely Bombproof Input will bomb. Please appreciate, however, that if committed, those are programmer-- not user--errors.
The Absolutely Bombproof Input Routine
The Absolutely Bombproof Input routine itself uses GETs to compartmentalize the individual characters of the INPUT line in separate string array locations. But first, line 1110 must null out any previously formed INPUT strings and arrays. Setting H1 = H in line 1120 "remembers' the original value of H, which changes as the routine proceeds. Line 1130 sets a guard against accidentally "backing out' of the alloted space for the INPUT. Line 1140 places the cursor at the beginning of the INPUT space, and advances its horizontal position as H is incremented with each successive pass through the INPUT-building loop.
At line 1150, characters are gathered one at a time with GET C$ (H) into the C$ array which eventually will be concatenated into the full INPUT statement, I$. Line 1160 looks for a RETURN, signalling all desired characters have been INPUT.
Line 1170 seeks the back arrow, and if it had been entered, sets a temporary TC$ array character to replace the C$ array variable that is being back-erased. At line 1180, a check is performed to see if the maximum allotted length for the INPUT has been reached, and if true, the bell sounds and no more characters are accepted.
Lines 1190 and 1200 are concerned with entry of forward arrows. First, 1190 checks the nature of the character in the temporary TC$ array position which may have been retrieved by a forward arrow. If it is not really a character, i.e., if it is null ("'), then it is set to a true space, CHR$ (32). Otherwise, separate words in the final INPUT statement might bunch up without intervening spaces. Line 1200 now can use forward arrows to copy back into the "real' C$ array any temporary TC$ array characters which may have been set previously by back arrows. The final filter takes place at line 1210, which refuses INPUT of any control character.
At last, in line 1220, the current C$ array character is accepted, and displayed in its proper position on the screen. Line 1230 increments the horizontal position counter and returns to the beginning of the loop to fetch the next character.
The routine ends at line 1240, which is reached only after a RETURN has been encountered. All the C$ array characters are now assembled into the final INPUT statement, I$, which is delivered to the main program for use as the programmer wishes.
Program Notes
Absolutely Bombproof Input was written in Applesoft on an Apple II Plus with 48K RAM, DOS 3.3, and an Integer card. The length of the routine (lines 1000-1240) is 584 bytes, including all remarks. When transcribing, I suggest you include the REMs in lines 1030-1090, since they describe what the routine requires from the main program.
I have found Absolutely Bombproof Input to be very malleable. By adding a statement or two, I have been able, for example, to make it accept only letters or only numbers. It could be made to demand that no spaces be in the entry, that specific combinations of characters be entered in order, or that entries be at least a certain number of characters long. My subroutine collection now includes a disk full of variations on Absolutely Bombproof Input, all of which are readily available to fill the particular needs of a program in development.
Table: Listing.