Hi Madscijr, here's some code which Steve drew up for me a while ago and it helped a lot, hope it's what you could be looking for.
And oh yes, bplus also gave me a neat addition to this phone record demo where he explained how you could put a Random File within a Random File where I had been working with multiple additional entries like multiple phone numbers. I haven't found that example code but if this is what you are looking for I'll try to find that example as well?
Code: (Select All)
_Title "Random Access File Demo"
Type Person_Type 'a type to hold your records
FirstName As String * 20
LastName As String * 20
Phone As _Unsigned _Integer64
End Type
Dim PhoneRecord As Person_Type 'and a variable to reference that type
Open "Phone Database" For Random As #1 Len = Len(PhoneRecord) 'open file at the length of one of those records.
Do
Cls
RecordLimit = LOF(1) \ Len(PhoneRecord) 'the number of records in your file.
Print "Record"; Tab(5); "Last Name"; Tab(30); "First Name"; Tab(55); "Phone Number"
For i = 1 To RecordLimit
Get #1, i, PhoneRecord 'get the whole record
Print i; Tab(5); PhoneRecord.LastName; Tab(30); PhoneRecord.FirstName; Tab(55); PhoneRecord.Phone
Next
Print
Print "What to do: 1)Add a record"
Print " 2)Delete a record"
Print " 3)Edit a record"
Print " 4)QUIT"
Do
a = Val(Input$(1))
Loop Until a > 0 And a < 5
Print a
Print
Select Case a
Case 1 'add a record
RecordLimit = RecordLimit + 1
Print "Adding Record #"; RecordLimit
Input "Enter Last Name:"; PhoneRecord.LastName
Input "Enter First Name:"; PhoneRecord.FirstName
Input "Enter Phone Number:"; PhoneRecord.Phone
Put #1, RecordLimit, PhoneRecord
Case 2 'delete a record
Input "Which record to delete?"; DeleteRecord
For i = DeleteRecord To RecordLimit - 1 'shift all records from deletion point on back one spot
Get #1, i + 1, PhoneRecord
Put #1, i, PhoneRecord
Next
Close #1
a$ = Space$(Len(PhoneRecord) * (RecordLimit - 1)) 'soace for all but the last record
Open "Phone Database" For Binary As #1
Get #1, 1, a$ 'get the whole database (minus the deleted record)
Close #1
Open "Phone Database" For Output As #1: Close 'delete the old database
Open "Phone Database" For Binary As #1 'save the new database to the drive.
Put #1, 1, a$
Close #1
Open "Phone Database" For Random As #1 Len = Len(PhoneRecord) 'open file at the length of one of those records.
Case 3 'edit a record
Input "Which Record to edit?"; editrecord
If editrecord > 0 And editrecord <= RecordLimit Then
Print "Editing Record #"; editrecord
Input "Enter Last Name:"; PhoneRecord.LastName
Input "Enter First Name:"; PhoneRecord.FirstName
Input "Enter Phone Number:"; PhoneRecord.Phone
Put #1, editrecord, PhoneRecord
Else
Print "Invalid record number."
End If
Case 4 'system
End Select
Loop
And oh yes, bplus also gave me a neat addition to this phone record demo where he explained how you could put a Random File within a Random File where I had been working with multiple additional entries like multiple phone numbers. I haven't found that example code but if this is what you are looking for I'll try to find that example as well?