SEEK

From MCS Wiki AVR
Revision as of 00:53, 12 February 2013 by Admin (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

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 file pointer must be set too.

 

This function returns the position of the next Byte to be read or written. If an error occurs, 0 is returned. Check DOS-Error in variable gbDOSError.

 

The statement also returns an error in the gbDOSerror variable in the event that an error occurs.

You can for example not set the file position behinds the file size.

 

In VB the file is filled with 0 bytes when you set the file pointer 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.

 

 

Notice.jpg
 In QB/VB you can use seek to make the file bigger. When a file is 100 bytes long, setting the file pointer to 200 will increase the file with 100 bytes. By design this is not the case in AVR-DOS.

 

 

 

See also

INITFILESYSTEM , OPEN , CLOSE, FLUSH , PRINT, LINE INPUT, LOC, LOF , EOF , FREEFILE , FILEATTR , BSAVE , BLOAD ,KILL , DISKFREE , DISKSIZE , GET , PUT , FILEDATE , FILETIME , FILEDATETIME , DIR , FILELEN , WRITE , INPUT

 

 

 

ASM

Function

Calls

_FileSeek

 

Input

r24: filenumber

X: Pointer to Long-variable, which gets the result

Output

r25: Errorcode

C-Flag: Set on Error

 

Statement

Calls

_FileSeekSet

 

Input

r24: filenumber

X: Pointer to Long-variable with the position

Output

r25: Errorcode

C-Flag: Set on Error

 

 

 

Partial 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

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language