15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

270<br />

Storing Varying Size Data in Untyped Files<br />

Inside the WHILE loop is the BlockRead command, which tells the computer<br />

to read one (1) block of data at a time (when each block of data is<br />

defined in size by the Reset command), as shown in Figure 8-4.<br />

Figure 8-4:<br />

The<br />

computer<br />

can retrieve<br />

data from an<br />

untyped file<br />

in blocks or<br />

chunks.<br />

To retrieve data from an untyped file, the computer<br />

retrieves a fixed chunk of data at a time.<br />

After the BlockRead command retrieves data from the file identified by the<br />

myFile variable, it stores this data in a Storage variable. The ShowMessage<br />

command displays the value of the Storage variable on-screen.<br />

Reading an untyped file from start to finish can be as slow and cumbersome<br />

as reading an entire text file from start to finish. So as a second way to retrieve<br />

data from an untyped file, you can use a pointer to “point” to different data<br />

blocks.<br />

For example, suppose you use the Reset command to define a block of 5<br />

bytes:<br />

Reset(myFile, 5);<br />

This command divides an untyped file into 5-byte blocks.<br />

To access an untyped file, like a random-access file, you can use the Seek<br />

command, which defines which untyped file to use and which data chunk to<br />

retrieve like this:<br />

Seek(myFile, 3);<br />

This command tells the computer to use the untyped file identified by the<br />

myFile variable and retrieve all the data in the third block of data, as shown<br />

in Figure 8-5.<br />

After the computer finishes retrieving data from the file, it needs to close the<br />

file by using the CloseFile command:<br />

CloseFile(myFile);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!