13.07.2015 Views

Turbo Basic

Turbo Basic

Turbo Basic

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

double-precision values into Microsoft-format strings that can then be written to afile.The major benefit of random files is implied in their name: Every record in thefile is available at any time. For example, in a database of 23,000 alumni, a programcan go straight to record 22,709 or 11,663 without reading any others. This capabilitymakes it the only reasonable choice for large files, and probably the betterchoice for small ones, especially those with relatively consistent record lengths.Random files can be wasteful of disk space, because space is allocated for thelongest possible field in every record. For example, including a comment field of100 bytes makes every record take an extra 100 bytes of disk space, even if only onein a thousand uses it.On the other extreme, if records are consistent in length, especially if they containmostly numbers, random files can save space over the equivalent sequentialform. In a random file, every number of the same type (integer, long integer, singleprecision, double precision) occupies the. same amount of disk space. For example,the following five single-precision values each require 4 bytes (the same space theyoccupy in memory):o1.660565E-2715000.1641623000000By contrast, in a sequential file, numbers require as many bytes as they haveASCII characters when PRINTed, plus one for the delimiting comma. For example:WRITE #1, 0;0takes 3 bytes, andPRINT #1, 0;0takes 6 bytes, andPRINT #1.660565E-27takes 13 bytes.The modest price you pay for the benefits of random files is a bit of extra processingnecessary to get strings and numbers into and out of a form that the random fileroutines can handle.You can create, write, and read random files using the following steps:1. OPEN the file and specify the length of each record.OPEN fi 1 espec AS [#J fi 7 enum LEN = record. size<strong>Turbo</strong> <strong>Basic</strong>: The Language 105

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

Saved successfully!

Ooh no, something went wrong!