Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
INPUTnone!851.0 to 7.0Statement

 
Syntax 
INPUT [ prompt ; ] variable [ , variable ] ...
 
ParametersTypeLegal Value(s)Default ValueNote(s)
promptStringany Must be a literal string -- no variable allowed!
variableString or numericany except reserved variableType must be valid for the data that comes in

 
 
Purpose 
Data input; always from the terminal (screen/keyboard).

 
 
Remarks 
This statement reads one or more values from the "terminal" which is to say the keyboard/screen.  These steps are executed:
  1. The prompt (if any) is printed on the screen followed by a question mark (?) and a space.
  2. The cursor is enabled on the screen.
  3. Data is read from the keyboard and echoed on the screen until Return/Enter is pressed.
  4. The cursor is disabled on the screen.
  5. BASIC parses the data entered and assigns value(s) to the specified variable(s).
  6. If the entered data is not valid for the variable's type, ?REDO FROM START is printed and BASIC goes back to step 1.
  7. If more variables are requested than the user enters, a double question mark (??) is printed and BASIC goes back to step 2.
  8. If data remains after all variable(s) have been assigned, ?EXTRA IGNORED is printed.
One interesting exception to step 7 is that if the user presses Return/Enter immediately without typing anything, BASIC does not request more data but assigns a null (if string) or zero (if numeric) to all variable(s).
 
For some unknown reason, the prompt must be a literal string.  SYNTAX ERROR is generated if a string variable is specified.  A work-around for this problem is to use PRINT prompt ; : INPUT variable... This works pretty well, except ?REDO FROM START (should it occur) will not print the prompt again.
 
Each datum read from the terminal must be compatible with each variable's type.  So a string variable must be specified if text is to be read.  A numeric variable (integer or float) is sometimes used to read numeric values, but often a string variable will be used in these cases too.  This is because if unexpected (non-numeric) characters appear when trying to input into a numeric variable, a ?REDO FROM START is generated.  Using a string variable, the (possibly mal-formed) data can be read without error and then tested and converted into a numeric value.
 
Multiple variables read from the terminal must be seperated with a comma (,).  If a colon (:) is found, it and everything after will be ignored/lost.  This will lead to either ?EXTRA IGNORED or ?? or depending if the colon was encounter while assigning the last variable or not.  Leading spaces in the input will be ignored.  If a comma, colon, or leading space(s) are needed in an input string, the user must surround the string with double-quotes(").  Exception to this rule is the ending double-quote may be omitted if no more variables need to be assigned.  There is no way to input a literal double-quote, ASCII Null, or a carriage return.
 
Although Commodore BASIC allows strings to be up to 255 characters in length, the length of all strings combined (in the case of multiple variables) may not be longer than the system's input buffer (this varies by computer model).  So if the system has an 80-character input buffer, and two strings are requested, a not-quite-accurate error of STRING TOO LONG would appear if the user typed a string of 40 characters for each variable.  This because 40+40 (the two strings) plus 1 for the comma that seperates them, is more than 80.
 
Because of this complex behavior, it is not un-common to see programs that use GET (or INPUT#) instead of INPUT.  Or at the very least, limit themselves to one variable per INPUT statement.  Along the same lines, several "INPUT replacement" routines have been published in Commodore magazines.
 
INPUT may only be used as a statement in a program.  Outside of a program it will generate ILLEGAL DIRECT error. 
 
Example:
NEW

READY.
10 INPUT "NUMBER, TEXT"; N, T$
20 PRINT N, T$
RUN
NUMBER, TEXT? X,Y (user input)
?REDO FROM START
NUMBER, TEXT? 1, A:B (user input)
?EXTRA IGNORED
 1        A
 
READY.
RUN
NUMBER, TEXT? 1, "A:B (user input)
 1        A:B
 
READY.
  
 
 
Compare With 

 
 
Contrast With 
 
© H2Obsession, 2014