Name
EOF Function
Class
Microsoft.VisualBasic.FileSystem
Syntax
EOF(filenumber)-
filenumber Use: Required
Data: 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
filenumbermust be an Integer that specifies a valid file number.If a file is opened for binary access, you cannot use
EOFwith theInputprocedure. Instead, useLOFandLoc. If you want to useEOF, you must use FileGet rather thanInput. In this case,EOFreturnsFalseuntil 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)
Debug.WriteLine(sLine)
LoopProgramming Tips and Gotchas
EOFallows 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
EOFwill therefore always returnTruewhen testing files opened with their modes set equal to eitherInputorAppend.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access