Line Input # Statement

Reads a string from an opened file and assigns it to a variable of the String type.

Syntax

Line Input #filenumber, varname

The Line Input # statement syntax has the following parts:

Part Description
filenumber Required, any valid file number.
varname Required, any legal variable name of Variant or String type.

Remarks

Data read with the Line Input # statement are normally written to file with the Print # statement.
The Line Input # statement reads by one symbol at a time until it reaches the carriage return symbol (Chr(13)) or the combination of carriage return and line feed symbols (Chr(13) + Chr(10)). When the string is assigned to the variable, the carriage return and line feed symbols are discarded.

Example

In this example the Line Input # statement reads a string from a file and assigns it to a variable. It's assumed that the TESTFILE file exists and contains several lines of text.

Dim TextLine
Open "TESTFILE" For Input As #1 ' Opens file.
Do While Not EOF(1)             ' Loop until the end of file.
    Line Input #1, TextLine     'Inputs string into variable.
    Trace TextLine              'Outputs the string into Output window.
Loop
Close #1                        ' Closes file.

See Also

Input # Statement, Chr Function