Loc Function |
Named Arguments
No
Syntax
Loc(filenumber)
filenumber
Use: Required
Data Type: Integer
Any valid file number.
Return Value
A Long integer.
Description
Determines the current position of the file read/write pointer.
Rules at a Glance
If you have opened the file in random mode, Loc returns the record number of the last record read or written.
If you have opened the file in input or output mode (sequential), Loc returns the current byte position in the file divided by 128.
If you have opened the file in binary mode, Loc returns the position of the last byte read or written.
Example
Dim hFile As Integer Dim lngPtr As Long, lngFileLen As Long Dim strBuffer As String hFile = FreeFile() Open "loc.bin" For Binary As #hFile lngFileLen = LOF(hFile) Do While lngPtr < lngFileLen strBuffer = strBuffer & Input(1, hFile) lngPtr = Loc(hFile) Loop Close #hFile Text1.Text = strBuffer
Programming Tips and Gotchas
For sequential files, the return value of Loc isn't required and shouldn't be used.
See Also
- Open Statement
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.