Siebel VB Language Reference > VB Language Reference >

Seek Function

This standard VB function returns the current file position for an open file.





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


The position in the file for the next operation.


For files opened in random mode, Seek returns the number of the next record to be read or written. For other modes, Seek returns the file offset for the next operation. The first byte in the file is at offset 1, the second byte is at offset 2, and so on. The return value is a long.


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)
         Seek 1,y
      End If
      msgtext = msgtext & newline & testscore
   Close #1
      Kill "c:\temp001"
End Sub

See Also

Get Statement
Open Statement
Put Statement
Seek Statement

Siebel VB Language Reference