Commas And Colons In Applesoft Strings:
An Easy Way To Use Them
Donald W. Watson
Commas and colons are not allowed with Applesoft strings — and this can be troublesome at times. Here's a solution. Also included is a program for Apple II disk users.
The Keyboard Problem
INPUT X$ is the convenient instruction for entering strings with an Applesoft II BASIC program; however, the string to be entered under the variable name X$ may not contain commas or colons. If either is present, the string will be truncated at the first occurrence when the RETURN key is pressed. The comma or colon and all characters following will be lost, and Applesoft will send the? EXTRA IGNORED message to the printer or to the screen.
In programs written for business use, it is often essential to include commas and colons in strings entered by the user. Programmers may not mind, but consider the user's frustration on learning that he or she cannot use commas or colons in places where they are normally required for acceptable format. For example, JONES, JAMES. J. is a common format for names in a list; RECEIPTS: might be a desirable heading for a list or group on a business report or ledger. In the latter example, the colon can be avoided by underlining the heading, but only at the expense of the user's choice, printer time, and perhaps report line space. Restricting alternatives is not in the user's interest. Here is a practical solution to the problem.
A Keyboard Solution
The Applesoft BASIC Programming Reference Manual is not much help on this subject although a clue to a solution is offered in Chapter 6 where the INPUT and GET instructions are defined and discussed. On page 68, a suggestion is made that "serious programmers GET numbers" by using a GET X$ instruction, where the keyboard response will be a string assigned to the string variable X$ when the RETURN key is pressed.
"String Entry" allows the entry of strings which can contain all characters from the Apple II keyboard. But String Entry does much more. The program contains routines which duplicate the most important Apple II string-editing capabilities (right- and left-arrow functions). It also provides some useful entry control functions for convenience in writing, displaying, and deleting strings.
A Free Keyboard
Type the listing into memory and proofread it carefully. When you're sure it is correct, SAVE it to a disk with a short name like STRENT. Then type RUN (with the program still in memory). The instruction line will appear. Experiment with the string entry process, noting that you now have the full freedom of the keyboard. You can enter strings with any characters you like, and you have normal editing functions with entry and deletion control. Best of all, the ?EXTRA IGNORED message never appears, and nothing is ignored unless you choose to have it ignored.
Most of String Entry (it's about 600 bytes long) can be used, with slight modification, in a larger program. If used to control string entry for more than one or two fields, it must be generalized for use as a subroutine, mostly by using integer variables V% and H% in the calling routine. VTAB V% and HTAB H% instructions can then be used in the subroutine to allow complete freedom when choosing a location for the string display on the screen.
The Apple II Disk Problem
The keyboard problem with commas and colons to be used in strings has been solved by avoiding the INPUT X$ instruction and using a GET X$ routine instead. But Apple II disk operations require the use of the INPUT X$ instruction to retrieve string data from a disk text file. If the string to be retrieved contains commas or colons, the ?EXTRA IGNORED message will occur; the string will be truncated as if it were entered from the keyboard in response to INPUT X$.
To correct this, try these two simple changes and some short additions to the String Entry program.
- Delete: GOTO 1020 from the end of line 1190.
- Add the lines below to the String Entry program.
- SAVE the modified and expanded program String Entry under its abbreviated name, STRENT.
1300 REM WRITE S* CONTENT TO DISK 1310 PRINT D$ ; "OPEN STRFILE" 1320 PRINT D$ ; "DELETE STRFILE" 1330 PRINT D$ ; " OPEN STRFILE" 1340 PRINT D$ ; "WRITE STRFILE" 1350 PRINT S$ 1360 PRINT D$ ; "CLOSE STRFILE" 1400 REM RETRIEVE S$ CONTENT FROM DISK 1410 S$ = " " 1420 PRINT D$ ; "OPEN STRFILE" 1430 PRINT D$ ; "READ STRFILE" 1440 INPUT S$ 1450 PRINT D$ ;"CLOSE STRFILE" 1500 REM DISPLAY RETRIEVED S$ CONTENT 1510 VTAB 20 : HTAB 8: PRINT TAB( 39); : HTAB 9 : PRINT S$: GOTO 1020
Save this expanded version to disk under the original filename STRENT.
Type RUN to execute the expanded program still in memory. The operator instruction line will appear. Using no commas and no colons, experiment with a few string entries. Each string entered will be stored on disk, and the program will echo the string by displaying it (as retrieved from the disk text file) a second time.
Now, perform a test. Enter a string containing a comma or colon, or both. Try NAME: JONES, JAMES J., for instance. When you have entered the string, it remains displayed at the string entry format line. It goes to the STRFILE at the disk under the permanent variable name S$. S$ in computer memory is nulled, S$ is retrieved from STRFILE, and the retrieved content of S$ is displayed on the screen.
But disaster strikes again. First, the dreaded ?EXTRA IGNORED message is displayed, and then the string is displayed in incomplete form. Read on for help.
An Apple II Disk Solution
The Apple II disk system (DOS 3.2 or DOS 3.3) will accept the contents of S$ as a literal string if the contents begin with a quote (") mark. The disk retrieval problem can be avoided by changing S$ temporarily with the statement S$ = CHR$(34) + S$.
To try this technique, just change line 1350 to the following:
1350 PRINT CHR$(34) + S$
SAVE the program once more under the filename STRENT and RUN it. Now, you will find that the test string NAME: JONES, JAMES J. can be correctly entered and correctly retrieved. And so can any string containing any characters from the Apple II keyboard, including commas and colons.
String Entry
1000 REM STRING ENTRY 1010 HOME : DIM C$(30):D$ = CHR$ (4) 1020 VTAB 15 : HTAB 9 : PRINT "TYPE " ; 1025 INVERSE : PRINT "E" ; : NORMAL : PRINT " TO ENTER NEW STRINS " ; 1030 GET E$ : VTAB 15 : HTAB 9 : PRINT TAB(39) 1040 VTAB 10 : HTAB 8 : PRINT "?" ; : FOR X = 1 TO 25 : C$(X) = "" : PRINT "." ; : NEXT X : HTAB 9 : X = 1 1050 IF X > 25 THEN PRINT CHR$ (7) : GOTO 1160 1060 GET C$ : IF X > 1 THEN 1090 1070 IF ASC (C$) = 13 THEN 1190 1080 IF ASC (C$) < 33 OR ASC (C$) > 90 THEN S$ = " " : GOTO 1040 1090 IF C$(1) = "0" AND X = 2 AND ASC (C$) = 13 THEN S$ = " " : GOTO 1190 1100 IF ASC (C$) = 13 THEN 1160 1110 IF ASC (C$) > 31 AND ASC (C$) < 91 THEN PRINT C$; : C$(X) = C$ : X = X + 1 : GOTO 1050 1120 IF ASC (C$) = B THEN X = X - 1 : HTAB (8 + X) : GOTO 1060 1130 IF ASC (C$) = 21 AND C$(X) < > " " THEN X = X + 1 : HTAB (8 + X) : GOTO 1050 1140 IF ASC (C$) = 21 THEN HTAB (8 + X) : GOTO 1060 1150 HTAB (8 + X) : GOTO 1040 1160 ST$ = " " : FOR L = 1 TO X - 1 : ST$ = ST$ + C$(L) : NEXT L 1170 R$ = RIGHT$ (ST$, 1) : IF ASC (R$) = 32 THEN ST$ = LEFT$ (ST$, LEN (ST$) - 1) : GOTO 1170 1180 S$ = ST$ 1190 VTAB 10 : HTAB 8 : PRINT TAB( 39); : HTAB 9: PRINT S$ : GOTO 1020