Seek, Seek()

Syntax

Seek [#]FileNumber, Count

Seek([#]FileNumber)

Remarks

The Seek statement controls where data is retrieved from a sequential file open for input, or where data is inserted into a file open for output or appending. For more information about sequential files, see Chapter 9, "More WordBasic Techniques," in Part 1, "Learning WordBasic."

Argument

Explanation

FileNumber

The number specified in the Open instruction that opened the file for input, output, or appending.

Count

The character position where data retrieval or insertion occurs. Note that line breaks and other delimiters, such as commas, are counted as characters.


The Seek() function returns the current character position in the sequential file. You can use the Seek() function to store the current character position before you close a sequential file, and the Seek statement to return to that position when you reopen the file.

Example

This example finds the first line beginning with the letter "P" in DATA.TXT and then displays a message box showing the entry and its character position in the file:


Open "DATA.TXT" For Input As #1
Input #1, name$
While Left$(name$, 1) <> "P"
    If Eof(1) Then
        MsgBox "No P names in the file."
        Goto finish
    End If
    n = Seek(#1)
    Input #1, name$
Wend
MsgBox "First P name is " + name$ + " at position" + Str$(n)
finish:
Close #1

See Also

Close, Eof(), Input, Input$(), Line Input, Lof(), Open, Print, Read, Write