FileSystem.Seek Method (Int32, Int64)
Returns a Long specifying the current read/write position in a file opened by using the FileOpen function, or sets the position for the next read/write operation in a file opened by using the FileOpen function. The My feature gives you better productivity and performance in file I/O operations than Seek. For more information, see FileSystem.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
Seek returns a value between 1 and 2,147,483,647 (equivalent to 2^31 – 1), inclusive.
The following describes the return values for each file access mode:
Number of the next record read or written
Binary, Input, Output, Append
Byte position at which the next operation occurs. The first byte in a file is at position 1, the second byte is at position 2, and so on.
This example uses the Seek function to return the current file position. The example assumes TestFile is a file that contains records of the structure Record.
Structure Record ' Define user-defined type. Dim ID As Integer Dim Name As String End Structure
For files opened in Random mode, Seek returns the number of next record.
FileOpen(1, "TESTFILE", OpenMode.Random) Do While Not EOF(1) WriteLine(1, Seek(1)) ' Write record number. FileGet(1, MyRecord, -1) ' Read next record. Loop FileClose(1)
For files opened in modes other than Random mode, Seek returns the byte position at which the next operation occurs. Assume TestFile is a file that contains several lines of text.
' Report character position at beginning of each line. Dim TextLine As String FileOpen(1, "TESTFILE", OpenMode.Input) ' Open file for reading. While Not EOF(1) ' Read next line. TextLine = LineInput(1) ' Position of next line. MsgBox(Seek(1)) End While FileClose(1)
This example uses the Seek function to set the position for the next read or write in a file.
For files opened in modes other than Random mode, Seek sets the byte position at which the next operation occurs. Assume TestFile is a file that contains several lines of text.
Available since 1.1