Visual Basic Language Reference  

LOF Function

Returns a Long representing the size, in bytes, of a file opened using the FileOpen function.

Public Function LOF(ByVal FileNumber As Integer) As Long

Parameter

FileNumber
Required. An Integer containing a valid file number.

Exceptions/Errors

Exception type Error number Condition
IOException 52 FileNumber does not exist.
IOException 54 File mode is invalid.

Remarks

Use the FileLen function to obtain the length of a file that is not open.

Example

This example uses the LOF function to determine the size of an open file. This example assumes that TESTFILE is a text file containing sample data.

Dim length As Integer
FileOpen(1, "C:\TESTFILE.TXT", OpenMode.Input) ' Open file.
length = LOF(1)   ' Get length of file.
Debug.WriteLine(length)
FileClose(1)   ' Close file.

See Also

EOF Function | FileLen Function | Loc Function | FileOpen Function | IOException