SEEK (function): Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "The '''SEEK''' function returns the current byte or record position in a file. {{PageSyntax}} :: byte = SEEK(filenumber&) * Filenumber is the number of an OPEN file in any mode. * In RANDOM files SEEK returns the current record position. * In BINARY or sequencial files SEEK returns the current byte position(first byte = 1). * Since the first file position is 1 it may require adding one to an offset value when documentation uses that position as 0. * Devic...") |
No edit summary |
||
Line 1: | Line 1: | ||
The '''SEEK''' function returns the | The '''SEEK''' function returns the byte or record position in a file, which is read or written next. | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: | : {{Parameter|byte}} = [[SEEK (function)|SEEK]]({{Parameter|filenumber&}}) | ||
* | {{PageParameters}} | ||
* In [[RANDOM]] files SEEK returns the | * {{Parameter|filenumber&}} is the number of an [[OPEN]] file in any mode. | ||
* In [[BINARY]] or sequencial files SEEK returns the | * In [[RANDOM]] files '''SEEK''' returns the record position to read or write. | ||
* In [[BINARY]] or sequencial files '''SEEK''' returns the byte position to read or write (first byte = 1). | |||
* Since the first file position is 1 it may require adding one to an offset value when documentation uses that position as 0. | * Since the first file position is 1 it may require adding one to an offset value when documentation uses that position as 0. | ||
* Devices that do not support SEEK (SCRN, CONS, KBRD, COMn and LPTn) return 0. | * Devices that do not support SEEK (SCRN, CONS, KBRD, COMn and LPTn) return 0. | ||
=== Notes === | |||
* Don't confuse the '''SEEK''' position with the [[LOC]] position !! | |||
** '''SEEK''' is the byte or record prosition to read or write {{Text|next|red}}. | |||
** '''LOC''' is the {{Text|last|red}} read or written byte or record prosition. | |||
{{PageExamples}} | |||
;Example:Demonstrate the difference between [[LOC]] and '''SEEK''' positions in a file. | |||
{{CodeStart}} | |||
OPEN "readme.md" FOR BINARY AS #1 | |||
PRINT LOC(1) 'LOC returns 0, as we didn't read something yet | |||
PRINT SEEK(1) 'SEEK otherwise returns 1, as it's the first byte to read | |||
GET #1, , a& 'now let's read a LONG (4 bytes) | |||
PRINT LOC(1) 'now LOC returns 4, the last read byte | |||
PRINT SEEK(1) 'and SEEK returns 5 now, the next byte to read | |||
CLOSE #1 | |||
END | |||
{{CodeEnd}} | |||
{{OutputStart}} | |||
0 | |||
1 | |||
4 | |||
5 | |||
{{OutputEnd}} | |||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[SEEK | * [[SEEK]], [[LOC]] | ||
* [[ | * [[GET]], [[PUT]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Revision as of 23:54, 24 February 2023
The SEEK function returns the byte or record position in a file, which is read or written next.
Syntax
- byte = SEEK(filenumber&)
Parameters
- filenumber& is the number of an OPEN file in any mode.
- In RANDOM files SEEK returns the record position to read or write.
- In BINARY or sequencial files SEEK returns the byte position to read or write (first byte = 1).
- Since the first file position is 1 it may require adding one to an offset value when documentation uses that position as 0.
- Devices that do not support SEEK (SCRN, CONS, KBRD, COMn and LPTn) return 0.
Notes
- Don't confuse the SEEK position with the LOC position !!
- SEEK is the byte or record prosition to read or write next.
- LOC is the last read or written byte or record prosition.
Examples
- Example
- Demonstrate the difference between LOC and SEEK positions in a file.
OPEN "readme.md" FOR BINARY AS #1 PRINT LOC(1) 'LOC returns 0, as we didn't read something yet PRINT SEEK(1) 'SEEK otherwise returns 1, as it's the first byte to read GET #1, , a& 'now let's read a LONG (4 bytes) PRINT LOC(1) 'now LOC returns 4, the last read byte PRINT SEEK(1) 'and SEEK returns 5 now, the next byte to read CLOSE #1 END |
0 1 4 5 |
See also