FileSystem.EOF Method (Int32)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static bool EOF(
	int FileNumber
)

Parameters

FileNumber
Type: System.Int32

Required. An Integer that contains any valid file number.

Return Value

Type: System.Boolean

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

Exception Condition
IOException

FileNumber does not exist.

IOException

File mode is invalid.

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 a whole 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.

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

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

.NET Framework
Available since 1.1
Return to top
Show: