Seek (function)

Syntax Seek (filenumber)
Description Returns the position of the file pointer in a file static to the beginning of the file.
Comments The filenumber parameter is a number that the Basic Control Engine uses to refer to the open file—the number passed to the Open statement. The value returned depends on the mode in which the file was opened:
File Mode Returns
Input Byte position for the next read.
Output Byte position for the next write.
Append Byte position for the next write.
Random Number of the next record to be written or read.
Binary Byte position for the next read or write.
The value returned is a Long between 1 and 2147483647, where the first byte (or first record) in the file is 1.
Example This example opens a file for random write, then writes ten records into the file using the PUT statement. The file position is displayed using the Seek Function, and the file is closed.
Sub Main()
  Open "test.dat" For Random Access Write As #1
  For x = 1 To 10
    r% = x * 10
    Put #1,x,r%
  Next x
  y = Seek(1)
  MsgBox "The current file position is: " & y
  Close
End Sub
See Also Seek (statement); Loc (function).