Get File Length Method
The Get File Length method returns the length in bytes of an open file. The file must already be open to use this method.
Format
Lof(filenumber)
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
filenumber |
The file number that the Open statement uses to open the file. |
Example
The following example opens a file and prints the contents of this file to the screen:
Sub Button_Click
Dim fname As String,fchar() As String
Dim x As Integer, msgtext As String, newline As String
newline = Chr(10)
fname = "d:\temp\trace.txt"
On Error Resume Next
Open fname for Input as #1
If Err <> 0 then
Exit Sub
End If
msgtext = "The contents of " & fname & " is: " _
& newline & newline
Redim fchar(Lof(1))
For x = 1 to Lof(1)
fchar(x) = Input(1,#1)
msgtext = msgtext & fchar(x)
Next x
Close #1
End Sub