LOF Function

Named Arguments

No

Syntax

LOF(filenumber)

filenumber

Use: Required

Data Type: Integer

Any valid file number.

Return Value

A Long integer.

Description

Returns the size of an open file in bytes.

Rules at a Glance

filenumber must be the number of a file opened using the Open statement.

Example

The following example shows how to use the LOF function to determine the length of a data file and to determine the number of records it contains:

Open sFileName For Random As #iFile Len = Len(udtCustomer)
iMaxRecs = LOF(iFile) / Len(udtCustomer)
For iRec = 1 To iMaxRecs   
   Get #1, iRec, udtCustomers(iRec)
Next iRec
Close #iFile

Programming Tips and Gotchas

LOF works only on an open file; if you need to know the size of a file that isn't open, use the FileLen function.

See Also

FileLen Function

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.