How to write a text input routine in Commodore BASIC

Published: May 8, 2018, 1:35 p.m.


\nIn this screencast I’ll show you how to write your own INPUT routine in Commodore BASIC. This comes in handy when you want to reject certain keys from being used when asking users for keyboard input. In my example I’m going to allow all alpha characters (A-Z), as well as SPACE, RETURN and the DELETE key.
\nHere’s the code:
\n.gist table { margin-bottom: 0; }
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
\n Learn more about bidirectional Unicode characters
\n
\n Show hidden characters
\n

\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n5 print
\n
\n
\n
\n10 w$=""
\n
\n
\n
\n20 print "(greater than)_";
\n
\n
\n
\n30 get a$:if a$="" then 30
\n
\n
\n
\n40 a=asc(a$)
\n
\n
\n
\n50 if a=13 then 200:rem return
\n
\n
\n
\n60 if a=32 then 110:rem space
\n
\n
\n
\n70 if a=20 then 300:rem backspace
\n
\n
\n
\n100 if a<65 or a>90 then 30
\n
\n
\n
\n110 print chr$(20);a$;"D";
\n
\n
\n
\n115 w$=w$+a$
\n
\n
\n
\n120 goto 30
\n
\n
\n
\n200 rem handle return
\n
\n
\n
\n210 print chr$(20)
\n
\n
\n
\n215 if w$="" then print:print"you typed
\n
\n
\n
\nnothing!":end
\n
\n
\n
\n220 print:print"you typed:":print w$
\n
\n
\n
\n230 end
\n
\n
\n
\n300 rem handle backspace
\n
\n
\n
\n305 if len(w$)=0 then 30
\n
\n
\n
\n310 print chr$(20);chr$(20);"D";
\n
\n
\n
\n320 w$=left$(w$,len(w$)–1)
\n
\n
\n
\n330 goto 30
\n
\n
\n
\n
\n
\n
\n view raw
\n
\n input.bas
\n

\n hosted with ❤ by GitHub
\n
\n
\n