Friendly VIC Inputs
Bill Pfeifer
Edit, Scan, and Input are special aids to help you painlessly enter lists or large amounts of information into your VIC. Errors won't result in hours of re-typing if you add Friendly VIC Inputs to your programs.
If you've ever run a lengthy program which required inputting a lot of string variables (such as an inventory sort, phone listing, etc.), you've probably had these experiences: 1. You discovered, halfway through the long list, that you entered one item twice. 2. You accidentally hit the return key twice, thereby entering a null string. 3. You misspelled something. 4. All of the above. Trying to correct these errors before sending the information to a tape or disk file can be tricky. The thought of having to re-do all that typing is most unpleasant. Here are some subroutines that will help take the drudgery out of entering, correcting, and re-entering your data.
Take a few minutes to enter the demo program into your computer. You can eliminate the REM statements to save keystrokes, but don't change the line numbers. Note that lines 310, 450, and 470 have two (2) spaces between the empty quotes, and line 90 has no space in the empty quotes. After you have entered the program and checked for errors, type RUN and hit RETURN. Now, let's walk through the program and see what's happening.
Easy Editing
The computer first asks for the number of entries (for our test, let's enter 10) and DIMensions A$ to this figure. We then enter a loop to input our data, using subroutine 310-350 as the INPUT routine (let's enter "THIS IS A TEST TO SEE HOW THE PROGRAM WORKS" — one word for each input prompt). Subroutine 310 looks rather involved for a simple input statement, but we'll see how this routine really shines, later on. After making each entry, we go back to line 90, and the computer checks to see if that entry was the letter E (for EDIT). For input prompt number 4, let's enter TYST and hit RETURN. For entry number 5, enter E and hit RETURN. Now the last entry is an E, and the program will jump to line 210, the EDIT routine.
If we know which entry number we want to correct, we simply enter that number. However, if we forget the number, or if it has scrolled off the screen, we enter 0. In the latter case, the program goes to yet another subroutine, the SCAN routine at line 370. This allows the user to scan up and down the list of data simply by holding down the f7 or f5 FUNCTION keys until the desired entry (along with its associated number) comes on screen. We note the number, hit the fl key, and enter this number in response to the prompt at line 210.
Armed with this information, the computer counts the number of characters in our selected entry, and tells us to make our changes and hit the RETURN key. Now the power of the INPUT subroutine comes into play. First, the routine prints the entry number, then the entry itself—TYST. Then the cursor is moved BACK to the LEFT of the entry, the input prompt is displayed, and the cursor is left flashing on the first letter of the entry, which is all neatly printed out for us. We need only move the cursor to the trouble spot (the letter Y), make our correction (E), and hit RETURN. The computer's screen editor then accepts the change and replaces the old entry with the new one — and we had to type only one letter! Obviously, this is a great help when dealing with long, complicated strings, and will eliminate the chance of making further errors, since we don't have to re-type the whole entry. Inserts and deletions are perfectly acceptable too, of course.
The computer then asks if we have any more changes to make — if we do, the EDIT routine repeats. If we have no more changes, the E we entered in input number 5 is wiped out, and we are asked for a new entry number 5. The whole input loop continues until all the entries are made, at which point the program goes on with its other chores (sorting, number crunching, filing, etc.). You can check to see if our correction was accepted by entering the following line in direct mode:
FOR I = 1 TO N: PRINT A$(I);: PRINT " ";: NEXT I
Changing Input Prompts
These subroutines can be called from any place in the program, but keep in mind that the cursor positioning in the INPUT routine works from the character count of the specified (or last used) entry. To get "new" input prompts, you must initialize A$(I) and CH, as shown in line 90, or you may get funny-looking prompts. E is given the value of I because the INPUT subroutine uses both the original loop (line 90) and the EDIT routine (line 210) as sources for printing the input prompt.
A sample application: you might want to use the sample program pretty much as is when initially entering your data. You then might re-scan all the entries to check for omissions and typos, then sort the data and scan once again. Now any duplications will be readily apparent (right next to each other), and you can make further corrections (using the INPUT routine) as required, and re-sort, if desired. You then may file or print out the results – one time, with all your corrections made, thanks to the help of the powerful screen editor of the computer.
One final note – on my VIC, the SCAN routine sometimes works only partially (the scan continues only when the f7 or f5 key is re-pressed). This happens only when I've entered a large number of strings and I don't have one of the RAM cartridges inserted. Apparently, the VIC needs lots of elbow room to juggle the strings around during the SCAN routine. Don't worry, though; if this happens, simply press and hold the function key again, and another batch of strings will come up on the screen.
10 REM INPUT WITH SCREEN EDIT DEMO 50 PRINT"{CLEAR}HOW MANY ENTRIES" : INPUT "WILL YOU BE MAKING" ; N : DIMA$(N) : PRINT 70 FOR I = 1TON 90 AS(I) = "" : E = I : CH = O : GOSUB310 : 1FA$(I) = "E" THENGOSUB210 110 PRINT : NEXT I : GOSUB 130 : END : REM CONTINUE ~ W/MAIN PROGRAM 130 PRINT : PRINT "MORE CHANGES (Y/N)?" : YS = "" 150 GETY$ : IF Y$ = "" THEN 150 170 IF Y$ = "Y" THEN 210 190 IF Y$ = "N" THEN I = I - 1 : RETURN 210 PRINT : PRINT "TITLE# (IF UNKNOWN," : INPUT "ENTER 0)" ; E 230 IF E = 0 THEN GOSUB 370 : GOTO 210 250 PRINT : PRINT "CHANGE ENTRY & {REV} RETURN {OFF}" : CH = LEN(A$(E)) 270 PRINT : GOSUB 310 290 PRINT : PRINT : S = 0 : E = 0 : GOSUB 130 : RETURN 310 PRINT "ENTRY#" E ; : PRINT " " ; : PRINT A$ (E); 330 FOR K = 1 TO (CH + 2) : PRINT "{LEFT}" ; : NEXT K 350 INPUT A$(E) : RETURN 370 PRINT : PRINT "HIT F7 KEY TO SCAN UP." : PRINT "HIT F5 KEY TO REVERSE." 390 PRINT "HIT F1 KEY TO STOP . " : S = 1 : POKE 650, 128 410 E$ = "" : PRINT 430 GET E$ : IF E$ = "" THEN 430 450 IF PEEK(197) = 63 THEN PRINTS " " ; : PRINT A$(S) : S = S + 1 : IF S = N + 1 THEN S = 1 470 IF PEEK(197) = 55 THEN PRINTS " " ; : PRINT A$(S) : S = S - 1 : IF S < 1 THEN S = N 490 IF PEEK(197) = 39 THEN POKE 650, 0 : RETURN 510 GOTO 410