INPUT(hash)
BASIC keyword | |
Keyword: | INPUT# |
Abbreviation: | I, <Shift>+N |
Type: | Command |
Token code: | $84 (132) |
Handling routine in BASIC ROM: |
---;--- $----;---- |
List of all BASIC keywords |
Remark: This article describes the BASIC command INPUT# in BASIC V2 on the Commodore 64.
Type: Command General Programming-Syntax: INPUT# <logic file number>,<variable>[,<variable>...]
The BASIC command INPUT# is used for reading data from a file stored on peripheral device media such as disk or tape. INPUT# reads complete data consisting of maximum 80 characters into variables and not only single characters as the GET# command.
Before INPUT# can be used, a channel to the destination device has to be established with the OPEN command. The INPUT# command must address the same logical file number as the preceding OPEN command. The dataset for a variable (string or numeric) always ends, when a comma , , a semicolon ; , a colon : or a Return character (= CHR$(13)
) occurs. These symbols can only be read within double quotes " . INPUT# can also read the screen memory, regarding any logical screen line (40 or 80 characters) until one of the aforesaid interrupting characters occurs. After each line the cursor automatically moves one line further.
If data are read into a numeric variable but do not have numeric content, the BASIC interpreter will report "?BAD DATA". Using string type variables only, can prevent this error report from occurring. If the 80 characters maximum for a variable is exceeded, the BASIC interpreter reports "?STRING TOO LONG". You can only use the INPUT# command within programs. If you type it in outside of a program, there will be an "?ILLEGAL DIRECT ERROR".
Examples[edit | edit source]
10 DIM A$(25) 20 PRINTCHR$(19);: OPEN 1,3 30 FOR X=1 TO 25: INPUT#1,A$(X): NEXT X 40 CLOSE 1 50 PRINTCHR$(147); 60 FOR X=1 TO 24: PRINT A$(X): NEXT X 70 PRINT A$(25) CHR$(19)
This program reads the whole 25 screen lines into the indicated string variables A$(X) (<-- program lines 20-40) and then reproduces them again on the screen.
10 OPEN, 1, 1, 0, "TESTFILE" 20 INPUT#1,A$(1) 30 INPUT#1,B$, C$, D$ 40 CLOSE 1
Reading a dataset from tape (for writing check PRINT#).
10 OPEN 2, 8, 4, "TESTFILE, SEQ, R" 20 INPUT#2,A$(1) 30 INPUT#2,B$, C$, D$ 40 CLOSE 2
Reading a dataset from the first disk drive (for writing check PRINT#).
10 OPEN 1,0 20 INPUT#1,A$ 30 PRINT A$ 40 CLOSE 1
Using the monitor as device. The advantage is: no INPUT prompt or no error message ?EXTRA IGNORED.
ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT