This documentation is archived and is not being maintained.

Loc Function

Returns a Long value specifying the current read/write position within an open file.

Public Function Loc(ByVal FileNumber As Integer) As Long

Parameter

FileNumber
Required. Any valid Integer file number.

Exceptions/Errors

Exception type Error number Condition
IOException 52 FileNumber does not exist.
IOException 54 File mode is invalid.

Remarks

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.

Example

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)

Smart Device Developer Notes

This function is not supported.

Requirements

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

EOF Function | LOF Function | Seek Function | File Access with Visual Basic Run-Time Functions | IOException Class

Show: