Home > CBM > BASIC > Keywords > Input num
180 Subpages: (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, 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

KeywordAbbreviationToken (hex)Version(s)Classification
INPUT#I{Shift+N}841.0 to 7.0Statement

 
Syntax 
INPUT# file_number variable [ , variable ] ...
 
ParametersTypeLegal Value(s)Default ValueNote(s)
file_numberInteger0~255 Must be the number of an open "file"
variableString or numericany except reserved variableType 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

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