LINE INPUT# statement

Purpose | Read line(s) from a sequential file into a string variable or string array, ignoring delimiters.
Syntax | LINE INPUT #filenum&, string_variable LINE INPUT #filenum&, Arr$() [RECORDS rcds] [TO count]

Remarks

filenum& is the file number, or variable containing a file number, given when the file was opened. string_variable is the string variable to be loaded with the data read from the file.

string_variable may be a fixed-length, nul-terminated, or dynamic string. For fixed-length and nul-terminated strings, data that is longer than the string is truncated to fit into the string. Dynamic strings receive the data without truncation. string_variable may not be a UDT variable, although fixed-length and nul-terminated UDT member variables are supported.

LINE INPUT# is intended for use with text files composed of lines terminated by CR/LF ($CRLF or CHR$(13,10)) sequences. It reads a line from the file and returns it, minus the CR/LF delimiter. Commas, quotation marks and other characters have no special meaning for LINE INPUT#, and are treated like any other text.

If the file consists of comma-delimited data items, INPUT# is likely to be more suitable then LINE INPUT#.

The second syntax definition of LINE INPUT# reads a file opened for INPUT, assigning full lines of text to each element of the array.

It is assumed the data is standard text, delimited by a CR/LF ($CRLF) or EOF (1A hex or $EOF). LINE INPUT# attempts to read the number of lines specified in the RECORDS rcds option, or the number of elements in the array, whichever is smaller.

The actual number of lines read is assigned to the variable specified in the optional TO count clause. FILESCAN is useful in conjunction, to determine the dimensioned size of the string array. EOF is set just as with single Line Input.

See also | EOF, FILESCAN, INPUT#, PRINT#

Example

SUB MakeFile

' Open a sequential file for output. Use PRINT#

' to write different data types to the file.

OPEN "LINEINP#.DTA" FOR OUTPUT AS #1

' Define some variables.

sVar$ = "There's trouble in River City, by George."

iVar% = 1000

fpVar! = 30000.12

' Write a line of text to the file.

PRINT# 1, sVar$; iVar%; fpVar!

CLOSE #1 'close the file

END SUB 'end procedure MakeFile

SUB ReadFile

'Open a sequential file for input, then use

'LINE INPUT # to read lines of different

'data types from the file.

OPEN "LINEINP#.DTA" FOR INPUT AS #1

StringVar$ = ""

'Input an entire line regardless of length or

'delimiters.

LINE INPUT #1, StringVar$

CLOSE #1 'close the file

END SUB 'end procedure ReadFile