Export (0) Print
Expand All

FileSystem.Loc Method

Returns a Long value that specifies the current read/write position in an open file.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static long Loc(
	int FileNumber
)

Parameters

FileNumber
Type: System.Int32

Required. Any valid Integer file number.

Return Value

Type: System.Int64
Returns a Long value that specifies the current read/write position in an open file.

ExceptionCondition
IOException

FileNumber does not exist.

IOException

File mode is invalid.

The Loc function is zero-based; using it to retrieve the first byte in a file will return 0.

The Loc function is provided for backward compatibility and may affect performance. For non-legacy applications, the My.Computer.FileSystem object provides better performance. For more information, see File Access with Visual Basic.

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 in an open file. This example assumes that MyFile is a text file that has several lines of sample data.

Dim location As Long 
Dim oneChar As Char
FileOpen(1, "C:\TESTFILE.TXT", OpenMode.Binary)
While location < LOF(1)
    Input(1, oneChar)
    location = Loc(1)
    WriteLine(1, location & ControlChars.CrLf)
End While
FileClose(1)

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft