Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help w/ RANDOM ACCESS FILES

Status
Not open for further replies.

goatsaregreat

Programmer
Mar 21, 2001
82
GB
I have to create a program for a VB course that is basically an address book. I could do it no problem with a database, but have no clue about RAF. I need to know whether or not I have create this file or not, how to write to it, and how to retrieve records from it. The course material is quite inadaquate at explaining this, so I thought of you guys. Please Advise. I do have a time limit on this. TIA.
 
Goatlover,
To open a raf - Open "filename" [For Random](not needed as it is the default) As [#]filenumber [Len = recordlength] (default is 128)

eg.
Open "C:\AddressBook.txt" as #5 Len = 25

If the file doesn't exist it is created

to write to the file
Put [#]filenumber, [recordnumber], variablename

where variablename = "the information to write"
if a recordnumber isn't specified the write occurs after the last read or write
eg.
Put #5, , strAddress

Get [#]filenumber, [recordnumber], variablename
gets the info and places it in variablename.

Close closes all files or
Close #5 closes file #5
 
Read the OPEN, SEEK, GET, and PUT descriptions in the help file. It's OK to be confused.

You cannot GET a record that has not been put. But you can put a record that has does not yet exist. Put past end of file extends the file, as does seek. Get past end of file raises an error

Make sure the variable types used to get match the variable types used to put. It keeps life simple, unless you're translating.

Create user defined type to represent your data record, It makes the get/put statements a breeze. Using Fixed length strings helps too. Oh yea, Len(MyVarOfUserDefinedType) returns the record length. You might need add to it to get the value needed in the open statement due to type and length descriptors.


Random acess comes in a number of flavors. The direct-access method provides a good start point. For this method you'll create an algorithm tieing the record id to a location in the file. Use something simple like [tt]record-id = seek-location.[/tt]



Wil Mead
wmead@optonline.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top