The ReadIntAt function will read an integer value (32bit) from any position within an open file channel.
So ReadIntAt lets you randomly access any piece of data within the file.
FACTS:
* Reading none sequential pieces of data can be slow * ReadIntAt only works with files opened with ReadFile * Integer values range from -2147483647 to 2147483647
Mini Tutorial:
This example creates a file and reads the with some various bits of data store in it, then read it's back again using the random access file commands.
; Create a file name File$=TempDir$()+"PB_TestFile.txt" ; Get a Free File Channel Index MyFile=GetFreeFile() ; CReate a File for writing data to WriteFile File$,MyFile ; Write some Byte data at a byte pos 100 WriteByteAt 1,100,255 ; Write some Word data at a byte pos 200 WriteWordAt 1,200,64000 ; Write some Integer data at a byte pos 300 WriteIntAt 1,300,111222 ; Write some Float data at a byte pos 400 WriteFloatAt 1,400,123.456 ; Write some Stringt data at a byte pos 500 WriteStringAt 1,500,"Play Basic" ; Write some Stringt data at a byte pos 600 WriteChrAt 1,600,"Hello World",11 ; Close this file channel CloseFile MyFile Print "============================" Print "Reading File Data:"+File$ Print "============================" ; Get a Free File Channel Index MyFile=GetFreeFile() ; Open a file to READ with READFILE ReadFile File$,MyFile ; Read and display byte from position 100 in this file Print ReadByteAt(myFile,100) ; Read and display the Word from position 200 in this file Print ReadWordAt(myFile,200) ; Read and display the Integer from position 300 in this file Print ReadIntAt(myFile,300) ; Read and display the Float from position 400 in this file Print ReadFloatAt(myFile,400) ; Read and display the String from position 500 in this file Print ReadStringAt$(myFile,500) ; Read and display the String from position 600 in this file Print ReadChrAt$(myFile,600,11) ; Close this file channel CloseFile MyFile ; Display the Size of the FIle Print "============================" Print "File Size:"+Str$(FileSize(file$)) Print "============================" If FileExist(file$) Then DeleteFile file$ ; Display the screen and wait for a key press Sync WaitKey |
This example would output. ============================ Reading File:C:Windows\temp\Pb_TestFile.txt ============================ 255 64000 111222 123.456 Play Basic Hello World ============================ File Size:611 ============================ |
|