Line Input # Statement

Description

Reads a line from an open sequential file and assigns it to a string variable.

Syntax

Line Input #filenumber,varname

The Line Input # statement syntax has these parts:

Part

Description

filenumber

Any valid file number.

varname

Valid string variable name.


Remarks

The Line Input # statement reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage return-linefeed sequence. Carriage return-linefeed sequences are skipped rather than appended to the character string.

See Also

Input # Statement.

Example

This example uses the Line Input # statement to read a line from a sequential file and assign it to a variable. For purposes of this example, assume that TESTFILE is a text file with a few lines of sample data.


Open "TESTFILE" For Input As #1    ' Open file.
Do While Not EOF(1)    ' Loop until end of file.
    Line Input #1, TextLine    ' Read line into variable.
    Debug.Print TextLine    ' Print to Debug window.
Loop
Close #1    ' Close file.