EOF Function

Description

Returns a value that indicates whether the end of a file has been reached.

Syntax

EOF(filenumber)

The filenumber named argument is any valid file number.

Remarks

Use EOF to avoid an error when attempting to get input past the end of a file.

False is returned unless the end of the file has been reached; then True is returned. When used with files opened for Random or Binary access, EOF returns False unless the last executed Get statement is unable to read an entire record; then True is returned.

See Also

Loc Function, LOF Function, Open Statement.

Example

This example uses the EOF function to detect the end of a file. For purposes of this example, assume that MyFile is a text file with a few lines of text.


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 Debug window.
Loop
Close #1    ' Close file.