Writing your own INPUT Routine in Commodore BASIC

Channel:
Subscribers:
29,700
Published on ● Video Link: https://www.youtube.com/watch?v=6StvaXx0SeQ



Duration: 22:56
201 views
10


In 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.

Here's the code:

5 print
10 w$=""
20 print "(greater than)_";
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 (smaller than) 65 or a (greater than) 90 then 30
110 print chr$(20);a$;"D";
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);"D";
320 w$=left$(w$,len(w$)-1)
330 goto 30

YouTube doesn't like "angle brackets", please replace where appropriate.

There's also a Gist for this code here: https://gist.github.com/versluis/93d97592e2680ccde2826e7957c04efa


SUPPORT MY PROJECTS
=====================
https://patreon.com/versluis
https://streamlabs.com/wpguru


LISTEN ON SPOTIFY
=================
3D Podcast
https://open.spotify.com/show/4IIh2WPBMRbjct6wdrGcTH?si=Tb7qVvEeQ2GxHpVjahGZNQ

Tech Podcast
https://open.spotify.com/show/3MSMNOruDorce08roxUy85?si=63KfmlDFTT-U1HzpNaa8pw







Tags:
Commodore
BASIC
C64
C128
Plus/4
VIC20
PET