19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

254 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

For recordNum = 1 To LOF(1) / Len(college)<br />

Also, the pair of statements<br />

lastRecord = LOF(1) / Len(college)<br />

Put #1, lastRecord + 1, college<br />

can be used to add a record to the end of the file.<br />

COMMENTS<br />

1. R<strong>and</strong>om-access files are also known as direct-access or relative files. Because<br />

each record has the same number of characters, the computer can calculate<br />

where to find a specified record <strong>and</strong>, therefore, does not have to search for it<br />

sequentially.<br />

2. Unlike sequential files, r<strong>and</strong>om-access files needn’t be closed between placing<br />

information into them <strong>and</strong> reading from them.<br />

3. R<strong>and</strong>om-access files do not have to be filled in order. For instance, a file can<br />

be opened <strong>and</strong> the first Put statement can be Put #n, 9, recVar. In this case,<br />

space is allocated for the preceding eight records.<br />

4. If the record number r is omitted from a Put or Get statement, then the record<br />

number used will be the one following the number most recently used in a Put<br />

or Get statement. For instance, if the line<br />

Put #1, , college<br />

is added to the program in Example 1 after the existing Put statement, then the<br />

information on Virginia Tech will occupy records 3 <strong>and</strong> 4 of the file COL-<br />

LEGES.TXT.<br />

5. Users often enter records into a r<strong>and</strong>om-access file without keeping track of the<br />

record numbers. If file #n is open, then the value of the function<br />

Loc(n)<br />

is the number of the record most recently written to or read from file n with a<br />

Put or Get statement.<br />

6. Each record in a r<strong>and</strong>om-access file has the same length. This length can be any<br />

number from 1 to 32767.<br />

7. When the statement Open “COLLEGES.TXT” For R<strong>and</strong>om As #1 Len =<br />

Len(college) is typed, the words “For R<strong>and</strong>om” can be omitted. The smart editor<br />

will insert them automatically.<br />

8. The decision of whether to store data in a sequential file or in a r<strong>and</strong>om-access<br />

file depends on how the data are to be processed. If processing requires a pass<br />

through all the data in the file, then sequential files are probably desirable. If<br />

processing involves seeking out one item of data, however, r<strong>and</strong>om-access files<br />

are the better choice.

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

Saved successfully!

Ooh no, something went wrong!