EOF Function 

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

Public Function EOF(ByVal FileNumber As Integer) As Boolean

Parameters

  • FileNumber
    Required. An Integer containing any valid file number.

Exceptions

Exception type Error number Condition

IOException

52

FileNumber does not exist.

IOException

54

File mode is invalid.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

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 FileGet function is unable to read an entire record.

With files opened for Binary access, an attempt to read through the file using the Input function until EOF returns True generates an error. Use the LOF 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.

Example

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

Dim TextLine As String
' Open file.
FileOpen(1, "TESTFILE", OpenMode.Input)
' Loop until end of file.
Do While Not EOF(1) 
' Read line into variable.
   TextLine = LineInput(1)
' Display result in a message box.
   MsgBox("End of file reached at " & TextLine)
Loop
FileClose(1)

Smart Device Developer Notes

This function is not supported.

Requirements

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Reference

FileGet Function
Loc Function
LOF Function
FileOpen Function
IOException