Seek Statement

Syntax

Seek [#]filenumber, position

filenumber

Use: Required

Data Type: Integer

Any valid file number.

position

Use: Required

Data Type: Long Integer

Any whole number between 1 and 2,147,483,647.

Description

Places the read/write marker at a given position where the next read/write operation should occur.

Rules at a Glance

  • If the file has been opened in random mode, position refers to the next record number that should be read or written.

  • In all other file open modes (append, binary, input, and output), position is the byte where the next read or write operation will start.

  • The use of a record number in any subsequent Get or Put statement overrides the position set by the Seek method.

  • The size of a file can be increased as the result of a write operation that is performed after a Seek statement in which position is beyond the end of the file.

  • If position is or negative, a runtime error is generated.

Programming Tips and Gotchas

Unused records in a random access data file aren't necessarily blank. For example, if you open a brand new data file, then perform a seek operation to record 10 and write a new record, the preceding nine records are filled with binary data that was present on the section of the disk used by the new file prior to its creation.

See Also

Get Statement, Open Statement, Print# Statement, Put Statement, Write# Statement

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.