When you are getting INPUT
in Commodore BASIC it always adds a question mark at the end of the string you want to show.
Is there a way to suppress the question mark when using the INPUT
command?
When you are getting INPUT
in Commodore BASIC it always adds a question mark at the end of the string you want to show.
Is there a way to suppress the question mark when using the INPUT
command?
Use the INPUT#
command.
The INPUT#
command is meant for non-interactive I/O on files or devices, i.e. reading from a file on disk, serial port, whatever. Because it is non-interactive, it will not display a prompt anywhere. The keyboard can be opened like any other I/O device, it has device number 0. Knowing that, the implementation is straightforward.
10 OPEN 1,0:REM OPEN DEVICE 0 AS FILE #1
20 PRINT"TYPE SOME TEXT:";
30 INPUT#1,A$
40 PRINT"YOU TYPED:";A$
Back in the day I wrote my own input code using GET. Over time I enhanced it to support various features. You start out with GET A$. Here is a simple one I just threw together:
10 NA$="":PR$="Name:"
20 GOSUB 50000
30 PRINT"Your name is ";NA$
40 END
50000 PRINT PR$;
50010 GET A$:IF A$="" THEN 50010
50020 IF A$=CHR$(13) THEN PRINT:RETURN
50030 IF A$<>CHR$(20) THEN 50050
50040 IF LEN(NA$)>0 THEN NA$=LEFT$(NA$,LEN(NA$)-1):? CHR$(157);" ";CHR$(157);
50050 IF A$>="a" AND A$<="z" THEN 50090
50060 IF A$>="A" AND A$<="Z" THEN 50090
50070 IF A$=" " THEN 50090
50080 GOTO 50010
50090 NA$=NA$+A$:PRINT A$;:GOTO 50010
BITD I had a blinking cursor implemented.
POKE19,32
just before issuing the INPUT
statement.
OPEN1,0:INPUT#1 A$:CLOSE1
the effect is the same, with a monitor program one can see that address 19 contains a 1
when the INPUT#
command is executed.
10 POKE 19,1
20 INPUT "ENTER NAME : ";A$
30 POKE 19,0
40 PRINT:PRINT "YOUR NAME IS ";A$
Is there a way to suppress the question mark when using the INPUT command?
No. There are also other problems with using INPUT
to get keyboard input. The Commodore PET had a problem where just typing Return would stop the program which probably also exists on the C64. You might be better using the GET
command.
Return
does not exist on the C64
Create your own custom input routine. The following one allows the input of letters A-Z and digits 0-9, although it could be further modified to limit the number of characters entered or to allow inserting the punctuation characters. The input string is stored in w$.
I am using VICE to write this program, so the underline characters in lines 20, 110, and 310 are achieved by pressing ShiftR.
5 print
10 w$=""
20 print "_";
30 get a$:if a$="" then 30
40 a=asc(a$)
50 if a=13 then 200:rem return
60 if a=32 then 110:rem space
70 if a=20 then 300:rem backspace
100 if a<48 or a>57 and a<65 or a>90 then 30
110 print chr$(20);a$;"_";
115 w$=w$+a$
120 goto 30
200 rem handle return
210 print chr$(20)
215 if w$="" then print:print"you typed nothing!":end
220 print:print"you typed: ";:print w$
230 end
300 rem handle backspace
305 if len(w$)=0 then 30
310 print chr$(20);chr$(20);"_";
320 w$=left$(w$,len(w$)-1)
330 goto 30