Description
Returns the current read/write position within a file opened using the Open statement.
Syntax
Seek(filenumber)
The filenumber named argument is any valid file number.
Remarks
Seek returns a value between 1 and 2,147,483,647 (equivalent to 2^31-1), inclusive. For files open in Random mode, Seek returns the number of the next record read or written. For files opened in Binary, Output, Append, or Input mode, Seek returns the byte position at which the next operation is to take place. The first byte in a file is at position 1, the second byte is at position 2, and so on.
See Also
Get Statement, Open Statement, Put Statement, Seek Statement.
Example
This example uses the Seek function to return the current file position.
' For files opened in random-file mode, Seek returns number of next ' record. Assume TESTFILE is a file containing records of the ' user-defined type Record. Type Record ' Define user-defined type. ID As Integer Name As String * 20 End Type Dim MyRecord As Record ' Declare variable. ' Open file in random-file mode. Open "TESTFILE" For Random As #1 Len = Len(MyRecord) Do While Not EOF(1) ' Loop until end of file. Get #1, , MyRecord ' Read next record. Debug.Print Seek(1) ' Print record number to Debug ' window. Loop Close #1 ' Close file. ' For files opened in modes other than random mode, Seek returns the ' byte position at which the next operation will take place. Assume ' TESTFILE is a file containing a few lines of text. Open "TESTFILE" For Input As #1 ' Open file for reading. Do While Not EOF(1) ' Loop until end of file. MyChar = Input(1,#1) ' Read next character of data. Debug.Print Seek(1) ' Print byte position to Debug ' window. Loop Close #1 ' Close file.