Loc (function)

Syntax

Loc(filenumber)

Description

Returns a Long representing the position of the file pointer in the given file.

Comments

The filenumber parameter is an Integer used by the Basic Control Engine to refer to the number passed by the Open statement to the Basic Control Engine .

The Loc function returns different values depending on the mode in which the file was opened:

 

File Mode

Returns

 

Input

Current byte position divided by 128.

 

Output

Current byte position divided by 128.

 

Append

Current byte position divided by 128.

 

Binary

Position of the last byte read or written.

 

Random

Number of the last record read or written.

Example

This example reads 5 lines of the autoexec.bat file, determines the current location of the file pointer, and displays it in a dialog box.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()
  file$ = "c:\autoexec.bat"
  Open file$ For Input As #1
  For x = 1 To 5
    If Not EOF(1) Then Line Input #1,lin$
  Next x
  lc% = Loc(1)
  Close
  MsgBox "The file byte location is: " & lc%
End Sub

See Also

Seek (function); Seek (statement); FileLen (function).

More information

L