Get File Offset Method
The Get File Offset method determines the current offset of a file. It returns a value depending on the following mode that it uses to open the file:
Random file. It returns the number of the last record read or written.
File opened in append, input, or output mode. It returns the current byte offset divided by 128.
File opened in binary mode. It returns the offset of the last byte read or written.
The offset starts at 0 in a random file or binary file. A position starts at 1. For more information, see Get File Position Method.
Format
Loc(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 creates a file of account numbers that the user enters. When the user finishes, it displays the offset of the file of the last entry that the user made:
Sub Button_Click
Dim filepos as Integer
Dim acctno() as Integer
Dim x as Integer
x = 0
Open "c:\TEMP001" for Random as #1
Do
x = x + 1
Redim Preserve acctno(x)
acctno(x) = 234
If acctno(x) = 0 then
Exit Do
End If
Put #1,, acctno(x)
Loop
filepos = Loc(1)
Close #1
Kill "C:\TEMP001"
End Sub