Seek (statement)


Seek [#] filenumber,position


Sets the position of the file pointer within a given file such that the next read or write operation will occur at the specified position.


The Seek statement accepts the following parameters:






Integer used by the Basic Control Engine to refer to the open file—the number passed to the Open statement.



Long that specifies the location within the file at which to position the file pointer. The value must be between 1 and 2147483647, where the first byte (or record number) in the file is 1. For files opened in either Binary, Output, Input, or Append mode, position is the byte position within the file. For Random files, position is the record number.


A file can be extended by seeking beyond the end of the file and writing data there.


This example opens a file for random write, then writes ten records into the file using the PUT statement. The file is then reopened for read, and the ninth record is read using the Seek and Get functions.

Sub Main()
  Open "test.dat" For Random Access Write As #1
  For x = 1 To 10
    rec$ = "Record#: " & x
    Put #1,x,rec$
  Next x

  Open "test.dat" For Random Access Read As #1
  Seek #1,9
  Get #1,,rec$
  MsgBox "The ninth record = " & x
  Kill "test.dat"
End Sub

See Also

Seek (function); Loc (function)

More information