O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

EOF Function

Class

Microsoft.VisualBasic.FileSystem

Syntax

EOF(filenumber)
filenumber (required; Integer)

Any valid file number

Return Value

A Boolean indicating when the end of the file has been reached

Description

Returns a Boolean indicating when the end of the file has been reached. Applies to files opened for binary, random, or sequential input.

Rules at a Glance

  • filenumber must be an Integer that specifies a valid file number.

  • If a file is opened for binary access, you cannot use EOF with the Input procedure. Instead, use LOF and Loc. If you want to use EOF, you must use FileGet rather than Input. In this case, EOF returns False until the previous FileGet procedure is unable to read an entire record.

Example

Dim fr As Integer = FreeFile(  )
Dim sLine As String
FileOpen(fr, "c:\data.txt", OpenMode.Input, OpenAccess.Read, _
         OpenShare.Default, -1)
Do While Not EOF(fr)
   sLine = LineInput(fr)
   Console.WriteLine(sLine)
Loop

Programming Tips and Gotchas

  • EOF allows you to test whether the end of a file has been reached without generating an error.

  • Because you always write data to sequential files at the end of the file, the file marker is always at the end of the file, and EOF will therefore always return True when testing files opened with their modes set equal to either Input or Append.

See Also

LOF Function

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required