Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎


Keyword Abbreviation Token (hex) Version(s) Classification
INPUT none! 85 1.0 to 7.0 Statement

INPUT [ prompt ; ] variable [ , variable ] ...
Parameters Type Legal Value(s) Default Value Note(s)
prompt String any   Must be a literal string -- no variable allowed!
variable String or numeric any except reserved variable Type must be valid for the data that comes in

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

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. 
20 PRINT N, T$
NUMBER, TEXT? X,Y (user input)
NUMBER, TEXT? 1, A:B (user input)
 1        A

NUMBER, TEXT? 1, "A:B (user input)
 1        A:B

Compare With  

Contrast With  
© H2Obsession, 2014