Random Access Files

 BBS: Inland Empire Archive
Date: 04-14-92 (13:03)             Number: 173
From: RICHARD VANNOY               Refer#: 66
  To: THOMAS HEAD                   Recvd: NO  
Subj: Random Access Files            Conf: (2) Quik_Bas
I ran your program exactly as you wrote it and it
worked fine, but since this is a sample and not your real
code, I'll offer some comments.

TH>' RAN1.BAS -- Put stuff in a random access file
TH>' By Thomas Head
TH>OPEN "TEST.DAT" FOR RANDOM AS #1

This defaults to a record length of 128 bytes.  If you have
short records, this will waste a lot of disk space.  If
you desire MORE than 128, then a 128 default will chop off
each record at 128 when you write the next record, and you
will lose data.  Pick the length of the longest record you
would expect (say 20) and set the record length like this:

   OPEN "TEST.DAT" FOR RANDOM AS #1 LEN = 20
                                    ^^^^^^^^
Also, you don't say so, but most random access data files
have more than one field.  If so, you need to define the
fields in a TYPE statement and DIM the TYPE, like...

TYPE PersonalData
   name AS STRING * 20
   age AS INTEGER
   salary AS SINGLE
END TYPE

DIM Stuff AS PersonalData

OPEN "TEST.DAT" FOR RANDOM AS #1 LEN = Stuff
                                 ^^^^^^^^^^^
LEN = Stuff will automatically set record length to
whatever length is required to hold what you defined in the
TYPE statement.

If you want more info on this, just ask.

> MegaMail 2.1b #0:640K = 4480K in Dog Bytes


--- WM v2.01/91-0012
 * Origin: Com-Dat BBS  Hillsboro, OR.  HST (503) 681-0543 (1:105/314)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET