# Line Input # statement
{: .no_toc }

Reads a single line from an open sequential file and assigns it to a **String** variable.

Syntax:
> **Line Input** **#** *filenumber* **,** *varname*

*filenumber*
: Any valid file number.

*varname*
: Valid **Variant** or **String** variable name.

Data read with **Line Input #** is usually written to a file with [**Print #**](/tB/Core/Print.md).

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 (**Chr**(13) + **Chr**(10)) sequence. Carriage return-linefeed sequences are skipped rather than appended to the character string.

Reading past the last line of the file raises run-time error 62 (*Input past end of file*), and leaves *varname* unchanged. Test for the end of the file with [**EOF**](/tB/Modules/FileSystem/EOF.md) before each read.

> [!NOTE] BETA 1045
> **Line Input #** raises run-time error -2147467259 (`&H80004005`) for a *filenumber* that is not open, where VB6 raises 52 (*Bad file name or number*).

### Example

This example uses the **Line Input #** statement to read a line from a sequential file and assign it to a variable. This example assumes that `TESTFILE` is a text file with a few lines of sample data.

```tb check_build
Dim TextLine
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 the Debug Console.
Loop
Close #1 ' Close file.
```

### See Also

- [**Open** statement](/tB/Core/Open.md)
- [**Close** statement](/tB/Core/Close.md)
- [**Input #** statement](/tB/Core/Input.md)
- [**Print #** statement](/tB/Core/Print.md)
- [**Write #** statement](/tB/Core/Write.md)
- [**EOF** function](/tB/Modules/FileSystem/EOF.md)
