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

INPUT#

Keyword Abbreviation Token (hex) Version(s) Classification
INPUT# I{Shift+N} 84 1.0 to 7.0 Statement

 
Syntax  
INPUT# file_number variable [ , variable ] ...
 
Parameters Type Legal Value(s) Default Value Note(s)
file_number Integer 0~255   Must be the number of an open "file"
variable String or numeric any except reserved variable Type must be valid for the data that comes in

 
 
Purpose  
Data input; typically from an external device.

 
 
Remarks  
This statement reads one or more values from the "file" associated with file_number and stores it/them in the specified variable(s).  Each datum read from the file 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 FILE DATA ERROR 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 items in the data stream of the file must be seperated with one of the following characters: a comma (,), a colon (:), or a carriage return (ASCII 13).  Because of this, a string which is to contain any of those characters must be surrounded by double-quotes (").  There is no way to input a literal double-quote.  Because of these issues, it is common to use GET# instead of INPUT#, although GET# is much slower.
 
Although Commodore BASIC allows strings to be up to 255 characters in length, a string read using INPUT# may not be longer than system's input buffer (this varies by computer model).  So if the system has an 80-character input buffer, then any "file" data which runs for more than 80 characters without a comma, colon, or carriage return will generate the not-quite-accurate error of STRING TOO LONG.  These are more good reasons to avoid INPUT#.
 
The "file" (or other input device) must have data available, or INPUT# may wait (possibly forever) until there is data.  With some devices, an undefined value may be read immediately when data is not available.
 
INPUT# may only be used as a statement in a program.  Outside of a program it will generate ILLEGAL DIRECT error. 
 
Example:
NEW
10 OPEN 1,0 : REM open the keyboard as file #1
20 INPUT# 1, N, T$ : PRINT
30 PRINT N
40 PRINT T$
50 CLOSE 1

RUN
TEXT,3 (user input)
?FILE DATA ERROR IN 20
READY.
RUN
3,TEXT (user input)
 3
TEXT

READY.
 
The example is using the keyboard as the input "file".  This is not typical, but it makes the example more concise.  Otherwise a file would have to be created and then opened... and this would require knowledge of your hardware and media.  Every CBM computer has a keyboard and they all work pretty much the same (good enough for the example).
  
 
 
Compare With  

 
 
Contrast With  
 
 
 
See Also  

© H2Obsession, 2014
Comments