LOF Function

See Also3MAJGDE              ExampleGU070M>Low

Returns the size of an open file in bytes.




The argument filenumber is the number used in the Open statement to open the file.  You can use any numeric expression71RISN that evaluates to the number of an open file.

LOF can be used only on disk files.

To obtain the length of a file that is not open, use the FileLen function.

See Also


FileLen Function3DE6YD9

Loc FunctionLANLOC

Open Statement103I7PS

LOF Function Example

The example uses LOF to determine the size of an open disk 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 Msg, NL                           ' Declare variables.

   NL = Chr(10)                          ' Define newline.

   MakeDataFile                          ' Create sample data file.

   Open "TESTFILE" For Input As #1       ' Open file just created.

   FileLength = LOF(1)                   ' Get length of file.

   Close #1                              ' Close file.

   Msg = "The length of the TESTFILE file just created is "

   Msg = Msg & FileLength & " bytes." & NL & NL

   Msg = Msg & "Choose OK to remove the sample data file."

   MsgBox Msg                            ' Display message.

   Kill "TESTFILE"                       ' Delete file from disk.

End Sub


Sub MakeDataFile ()

   Dim I                                 ' Declare variable.

   Open "TESTFILE" For Output As #1      ' Open file for output.

   For I = 0 To 200                      ' Generate random values.

      Print #1, Int(501 * Rnd)

   Next I

   Close #1                              ' Close file.

End Sub