Returns a Long value specifying the current read/write position within an open file.
Public Function Loc(ByVal FileNumber As Integer) As Long
Exception type | Error number | Condition |
---|---|---|
52 | FileNumber does not exist. | |
54 | File mode is invalid. |
The following describes the return value for each file access mode:
Mode | Return value |
---|---|
Random | Number of the last record read from or written to the file. |
Sequential | Current byte position in the file divided by 128. However, information returned by Loc for sequential files is neither used nor required. |
Binary | Position of the last byte read or written. |
This example uses the Loc function to return the current read/write position within an open file. This example assumes that MYFILE
is a text file with a few lines of sample data.
Dim location As Long Dim oneLine As String Dim oneChar As Char FileOpen(1, "C:\MYFILE.TXT", OpenMode.Binary) While location < EOF(1) Input(1, oneChar) location =Loc(
1)
Debug.WriteLine(location & ControlChars.CrLf) End While FileClose(1)
EOF Function | LOF Function | Seek Function |