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 |
| Keyword | Abbreviation | Token (hex) | Version(s) | Classification |
| INPUT# | I{Shift+N} | 84 | 1.0 to 7.0 | Statement |
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 |
Data input; typically from an external device.
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 (:), a carriage return (ASCII 13), or a null (ASCII 0). Because of this, a string
which is to contain a comma or colon must be surrounded by double-quotes (").
There is no way to input a literal double-quote, a carriage return, or a null. 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).
INPUT, FETCH, GET#,
JOY, LOAD, PEN,
POT, READ, RSPPOS,
SSHAPE
CHAR, CMD, GSHAPE,
PRINT#, SAVE, STASH
APPEND, CLOSE, DOPEN,
OPEN, RECORD
© H2Obsession, 2014 |