File Check And Improved Input
I would like to make my Applesoft BASIC program check to see if a file exists on a disk. I need this for a database program I am writing. If I have this feature, I can keep people from accidently deleting their work.
I also have a question about INPUT. In your February "Reader's Feedback," you told a Commodore 64 user about two POKEs that put quotation marks into the keyboard buffer before input strings. Can you do this in Applesoft BASIC?
James B. Sullivan
Here's a short example program that checks for an existing file. This program segment cannot be used as a subroutine (the ON ERR statement would destroy the return address.) The program keeps asking for a filename until you give one that doesn't exist.
14 5 REM test for an existing file 27 10 Input "enter file neme"; F$ 62 20 Ex = 0: ONERR GOTO 60 0A 30 PRINT CHR$ (4) "verify" F$ 8E 40 IF EX = 0 THEN PRINT "file exists, try again": GOTO 20 04 50 PRINT "file does not exist" 4A 5A GOTO 70 98 60 EX = 1: POKE 216, 0: GOTO 40 99 70 REM put the rest of your program here
The answer to the second question is no, you cannot POKE quotation marks into the keyboard buffer on the Apple. One way to allow commas and colons in an INPUT string is to use a custom subroutine for input. The program below uses a subroutine at line 890 for input. In addition to allowing commands, the delete key and left cursor key are active, and the Escape key allows you to restart input.
8B 100 REM subroutine to allows commas and colons in input AF 110 PRINT "test input "; F2 120 GOSUB 890: PRINT "you entered "AM$ 8F 130 END 84 890 PRINT "?"; 8E 900 GET A$: IF A$ = CHR$ (13) THEN 970 7D 910 IF A$ < > CHR$ (8) AND A$ < > CHR$ (127) THEN 940 27 920 IF LEN (AM$) < 2 THEN AM$ = "": GOTO 940 A9 930 AM$ = LEFT$ (AM$, LEN (AM$) - 1): GOTO 960 F4 940 IF A$ = CHR (27) THEN FOR I = 1 TO LEN (AM$): PRINT CHR$ (8);: NEXT : AM$ = "": GOTO 960 9C 950 AM$ = AM$ + A$ : AM$ = LEFT$ (AM$, 38) 36 960 PEINT A$; : GOTO 900 80 970 PRINT : RETURN