EOF Function

Purpose

Tests if the data pointer points to the end of a file.

Syntax

EOF(#n)

Description

EOF(#n) always acts on the file on the previously opened channel n, and returns -1 if the data pointer points to the end of this file or 0 if not.

Example

Auto a$, i%

OpenW 1 : Win_1.PrintWrap = True

Open App.Path & "\TEST.DAT" for Output As # 1

For i% = 1 To 100

Print # 1, Str$(i%, 3)`

Next i%

Close # 1

Open App.Path & "\TEST.DAT" for Input As # 1

Do Until EOF(# 1)

Input # 1, a$

Print ""; a$`

Loop

Close # 1

Kill App.Path & "\TEST.DAT" // Tidy up line

Opens TEST.DAT file in the application folder and reads its contents until the end of file.

Known Issues

In earlier versions, EOF() didn't work correctly with text files as "internal resource files" (those files that are included in the source code and which name begins with ":"): EOF() was true after reading the first line even if there are many more text-lines in the "internal resource file" (it is the required function of TextEOF to test for an end-of-text marker, not EOF). As of gfawin23.ocx version 2.341, this issue has been fixed.

The only workaround for this old error was to set up a Try...Catch structure around the file processing and use this in conjunction with the 'End of File reached' error message to emulate the function of EOF.

See Also

Loc(), Lof(), TextEOF

{Created by Sjouke Hamstra; Last updated: 08/03/2018 by James Gaite}