See Also Example
Returns a value during file input that indicates whether the end of a file has been reached.
Syntax
EOF(filenumber)
Remarks
The argument filenumber is the number used in the Open statement to open the file. You can use any numeric expression that evaluates to the number of an open file.
The EOF function returns True if the end of a file has been reached, and False if it has not. Use the EOF function with sequential files to test for the end of a file. This helps you avoid the error that occurs when you attempt to get input past the end of a file.
When used with Random or Binary files, EOF returns True if the last executed Get statement was unable to read an entire record; otherwise, it returns False.
Loc Function
LOF Function
Open Statement
The example uses the EOF function to detect the end of a sequential file. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim NL, TestVar, Msg ' Declare variables.
NL = Chr(10) ' Define newline.
MakeDataFile ' Create sample data file.
Open "TESTFILE" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Check for end of file.
Input #1, TestVar ' Read data.
Loop
Close #1 ' Close file.
Msg = "The last value read from the data file was "
Msg = Msg & TestVar & "." & NL
Msg = Msg & NL & "Choose OK to remove the created test file."
MsgBox Msg ' Display results.
Kill "TESTFILE" ' Delete file from disk.
End Sub
Sub MakeDataFile ()
Dim I ' Declare variable.
Open "TESTFILE" For Output As #1 ' Open file.
For I = 0 To 200 ' Generate random values
Print #1, Int((100) * Rnd) ' from 0 to 99.
Next I
Close #1 ' Close file.
End Sub