SEEK - Statement

SEEK(filenumber, position)

Repositions where the next operation in a file will occur.

filenumberThe number of the file (Integer).
positionThe byte position (Single).

* Sets the record of byte position of the open file associated with the filenumber.
* This changes the position of the record within the associated file.
* If you attempt a Seek operation to a negative or zero position, an error occurs.
* Performing a file-write operation after a Seek operation beyond the end of a file extends the file.
* Record numbers specified in Get and Put statements override file positioning performed by Seek.
* You can use the GET statement to read data from a text file into a record.
* You can use the INPUT statement to return the open stream of an Input or Binary file.
* You can use the LOF function to return the length or size of an open file, in bytes.
* You can use the OPEN statement to open a text file or csv file.
* You can use the PRINT statement to write data to a file opened with Sequential access (display formatted).
* You can use the PUT statement to write data from a record into a text file.
* You can use the SEEK Function to return the current read/write position within a file opened using the Open statement.
* You can use the WRITE statement to write data to a file opened with Sequential access.
* For the Microsoft documentation refer to

Type UserDefinedType 
 ID As Integer
 Name As String * 20
End Type

Sub Example()
Dim TheRecord As UserDefinedType
Dim MaxSize As Integer
Dim RecordNumber As Integer

Open "C:\Temp\MyText.txt" For Random As #1 Len = Len(TheRecord)
MaxSize = LOF(1) \ Len(TheRecord)

For RecordNumber = MaxSize To 1 Step -1
 Seek #1, RecordNumber
 Get #1, , TheRecord
Next RecordNumber

Close #1
End Sub

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top