# EOF
{: .no_toc }

Returns an **Integer** containing the **Boolean** value **True** when the end of a file opened for **Random** or sequential **Input** has been reached.

Syntax: **EOF(** *filenumber* **)**

*filenumber*
: *required* **Integer** containing any valid file number.

### Remarks

Use **EOF** to avoid the error generated by attempting to get input past the end of a file.

The **EOF** function returns **False** until the end of the file has been reached. With files opened for **Random** or **Binary** access, **EOF** returns **False** until the last executed **Get** statement is unable to read an entire record.

With files opened for **Binary** access, an attempt to read through the file by using the **Input** function until **EOF** returns **True** generates an error. Use the [LOF](/tB/Modules/FileSystem/LOF.md) and **Loc** functions instead of **EOF** when reading binary files with **Input**, or use **Get** when using the **EOF** function. With files opened for **Output**, **EOF** always returns **True**.

### Common Errors

| Error | When |
|---|---|
| [-2147467259 (`&H80004005`)](/Reference/Run-time-Errors.md#-2147467259), *Unspecified error* | *filenumber* is not the number of an open file |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *filenumber* is **Null** |

> [!NOTE] BETA 1045
> When *filenumber* is not the number of an open file, VB6 and 64-bit VBA raise error [52 (`&H34`)](/Reference/Run-time-Errors.md#52), *Bad file name or number*, instead.

### Example

This example uses the **EOF** function to detect the end of a file. This example assumes that `MYFILE` is a text file with a few lines of text.

```tb check_build
Dim InputData
Open "MYFILE" For Input As #1    ' Open file for input.
Do While Not EOF(1)    ' Check for end of file.
    Line Input #1, InputData    ' Read line of data.
    Debug.Print InputData    ' Print to the Debug Console.
Loop
Close #1    ' Close file.
```

### See Also

- [LOF](/tB/Modules/FileSystem/LOF.md) function
