O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

LOF Function

Class

Microsoft.VisualBasic.FileSystem

Syntax

LOF(filenumber)
filenumber (required; Integer)

Any valid file number

Return Value

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 FileOpen function.

Example

The following example shows how to use the LOF function to prevent reading past the end of a file in binary mode:

Dim fr As Integer = FreeFile(  )
Dim sChar As Char
FileOpen(fr, "c:\data.txt", OpenMode.Binary, OpenAccess.Read)

Do While Loc(fr) < LOF(fr)
    FileGet(fr, sChar)
    Debug.Write(Loc(fr) & ": ")
    Console.WriteLine(sChar)
Loop

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required