SEEK
Action
Function: Returns the position of the next Byte to be read or written
Statement: Sets the position of the next Byte to be read or written
Syntax
Function: NextReadWrite = Seek (#bFileNumber)
Statement: Seek #bFileNumber, NewPos
Remarks
bFileNumber |
(Byte) Filenumber, which identifies an opened file |
NextReadWrite |
A Long Variable, which is assigned with the Position of the next Byte to be read or written (1-based) |
NewPos |
A Long variable that holds the new position the filepointer must be set too. |
This function returns the position of the next Byte to be read or written. If an error occures, 0 is returned. Check DOS-Error in variable gbDOSError.
The
statetement also returns an error in the gbDOSerror variable in the event that
an error occurs.
You can for example not set the fileposition behinds the filesize.
In QB/VB the file is filled with 0 bytes when you set the filepointer behind the size of the file. For embedded systems this does not seem a good idea.
Seek and Loc seems to do the same function, but take care : the seek function will return the position of the next read/write, while the Loc function returns the position of the last read/write. You may say that Seek = Loc+1.
Difference with QB
In QB/VB you can use seek to make the file bigger. When a file is 100 bytes long, setting the filepointer to 200 will increase the file with 0 bytes. By design this is not the case in AVR-DOS.
ASM
Function |
_FileSeek |
|
Input |
r24: filenumber |
X: Pointer to Long-variable, which gets the result |
Output |
r25: Errorcode |
C-Flag: Set on Error |
Statement |
_FileSeekSet |
|
Input |
r24: filenumber |
X: Pointer to Long-variable with the position |
Output |
r25: Errorcode |
C-Flag: Set on Error |
Example
Open
"test.biN" For
Binary As
#2
Put #2
, B ' write a byte
Put #2
, W ' write a word
Put #2
, L ' write a long
Ltemp = Loc(#2)
+ 1 ' get the
position of the next byte
Print Ltemp ;
" LOC" ' store the
location of the file pointer
Print Seek(#2)
; " = LOC+1"
Close #2
'now open the
file again and write only the single
Open "test.bin"
For Binary
As #2
Seek #2
, Ltemp ' set the filepointer
Sn = 1.23 ' change the single value so we can
check it better
Put #2
, Sn = 1
'specify the file position
Close #2