Siebel VB Language Reference > VB Language Reference >

Seek Statement


Seek sets the position within an open file for the next read or write operation.

Syntax

Seek [#]filenumber, position

Argument
Description

filenumber

The number assigned in the Open statement to the file to be queried

position

An expression of type long representing the starting position of the next record number for a random read or write operation, or the byte offset from the beginning of the file

Returns

Not applicable

Usage

If you write to a file after seeking beyond the end of the file, the file's length is extended. Basic returns an error message if a Seek operation is attempted that specifies a negative or zero position.

For files opened in Random mode, position is a record number; for other modes, position is a byte offset. Position is in the range 1 to 2,147,483,647. The first byte or record in the file is at position 1, the second is at position 2, and so on.

Example

This example reads the contents of a sequential file line by line (to a carriage return) and displays the results. The second subprogram, CreateFile, creates the file C:\temp001 used by the main subprogram.

(general) (declarations)
Option Explicit
Declare Sub CreateFile

Sub CreateFile
   Rem Put the numbers 10-100 into a file
   Dim x as Integer
   Open "c:\temp001" for Output as #1
   For x = 10 to 100 step 10
      Write #1, x
   Next x
   Close #1
End Sub

Sub Button_Click
   Dim testscore as String
   Dim x
   Dim y
   Dim newline
   Call CreateFile
   Open "c:\temp001" for Input as #1
   x = 1
   newline = Chr(10)
   msgtext = "The test scores are: " & newline
   Do Until x = Lof(1)
      Line Input #1, testscore
      x = x + 1
      y = Seek(1)
      If y>Lof(1) then
         x = Lof(1)
      Else
         Seek 1,y
      End If
      msgtext = msgtext & newline & testscore
   Loop
   Close #1
      Kill "c:\temp001"
End Sub

See Also

Get Statement
Open Statement
Put Statement
Seek Function

Siebel VB Language Reference