Commodore Comma Conflicts
I have a Commodore 64. Whenever I try to INPUT something into a string using a comma, the computer rejects everything thereafter, including the comma. How do you enter commas in response to an INPUT statement?
Ronald Weber
INPUT is a versatile command, but you've run smack into its biggest limitation. You may not be aware of the intended purpose of the comma. For example, try this program:
10 INPUT "Name: Last, First";L$, F$ 20 PRINT "Your name is ";F$;" ";L$
When you run this, you can enter both your last and first name on the same line in response to the INPUT statement. You separate the items with commas. Alternately, you can press RETURN after the first entry, and a question mark appears for the next. It's sometimes very convenient to use the comma for this purpose. But if the INPUT statement does not require more than one entry, the comma makes no sense to the computer, and it reminds you that it didn't know what to do by displaying ?EXTRA IGNORED. Everything thereafter (including the comma) is seen as an errant second input and is therefore thrown out. You may have also noticed that colons behave much like commas, giving you ?EXTRA IGNORED.
Aside from programming your own special version of INPUT by using the GET command, there is one trick that lets you enter anything into an INPUT statement, even leading and trailing spaces (which are normally removed). Just start your entry with a quote. This will put you in quote mode, so be careful with cursor controls. Alternately, you could enter two quotes, then backspace with DELete to erase the second quote. This gives you the leading quote, but keeps you out of quote mode. INPUT accepts everything within quotes. Notice, though, that the quote marks are not included as part of the entry. Only what's inside the quotes will count. Also keep in mind that these limitations (or features) also apply to INPUT# with tape, disk, or other devices.
Sometimes the best solution is to just write your own version of the INPUT statement. Try this small subroutine with GOSUB 10000. It does not allow cursor controls (other than backspacing with DELete), but it will accept any printable character. The line typed as input is available in the variable IN$. No prompt is printed, so your main program should PRINT the question before calling this subroutine. Since a string is limited to 255 characters, the variable IL is set to 255 on line 10000. If you want a smaller limit, change line 10000, or just set IL in your main program, make IN$="", and GOSUB 100010.
10000 IN$ = "" : IL = 255 :rem 213 10010 PRINT "[<+>]{LEFT}"; :rem 65 10020 GET I$ : IF I$ = ""THEN 10020 :rem 25 10030 PRINT" {LEFT}"; : IN = ASC(I$) : IF IN = 13 THEN PRINT : RETURN :rem 23 10040 IF IN = 20 AND LEN(IN$)THEN IN$ = LEFT$(IN$,LEN(IN$)-1) : PRINT I$; : GOTO 10010 :rem 67 10050 IF(IN AND 127) < 32 OR LEN(IN$) = IL THEN 10010 :rem 250 10060 PRINT I$; : POKE 212, 0 : IN$ = IN$ + I$ : GOTO 10010 :rem 112