Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indexed files
#3
You want to open a file for Random (Access) and best if you set it with a fixed length record size. This allows you to read and write records to a record number.

Here is a demo for johnno for tracking Blood tests;
Code: (Select All)
'Tutorial (with help from Wiki):

' save this bas file in the folder where you want you BloodData.dat file to go first!

Type Blood
    date As String * 10
    level As Integer
    comment As String * 50
End Type

'Make a record:
Dim Shared Record As Blood, lenRecord&, nRecs&
lenRecord& = Len(Record)

' start up the data file
Open "BloodData.dat" For Random As #1 Len = lenRecord&


Record.date = "2022/11/18"
Record.level = 101
Record.comment = "This is my comment."

'Store a record:
Put #1, 1, Record

nRecs = LOF(1) / lenRecord&
Print "number recs:"; nRecs ' good 1 lets get it

' get record
Get #1, 1, Record
Print Record.date; ":"; Record.level; ", "; Record.comment

' stick another record in there
nRecs = nRecs + 1
Record.date = "2022/11/19"
Record.level = 105
Record.comment = "This is my next comment."
Put #1, nRecs, Record

' check records
nRecs = LOF(1) / lenRecord&
Print "number recs:"; nRecs ' good 1 lets get it

For i = 1 To nRecs
    Get #1, i, Record
    Print Record.date; ":"; Record.level; ", "; Record.comment
Next

You create a data entry form for entering the record to file file or reading records out.
b = b + ...
Reply


Messages In This Thread
Indexed files - by PhilOfPerth - 11-03-2023, 11:21 PM
RE: Indexed files - by a740g - 11-03-2023, 11:40 PM
RE: Indexed files - by bplus - 11-03-2023, 11:44 PM
RE: Indexed files - by bplus - 11-03-2023, 11:50 PM
RE: Indexed files - by TerryRitchie - 11-03-2023, 11:55 PM
RE: Indexed files - by bplus - 11-03-2023, 11:55 PM
RE: Indexed files - by SMcNeill - 11-04-2023, 12:29 AM
RE: Indexed files - by bplus - 11-03-2023, 11:57 PM
RE: Indexed files - by JamesAlexander - 11-04-2023, 01:20 AM
RE: Indexed files - by PhilOfPerth - 11-04-2023, 01:39 AM
RE: Indexed files - by mnrvovrfc - 11-04-2023, 02:21 AM
RE: Indexed files - by PhilOfPerth - 11-04-2023, 07:44 AM
RE: Indexed files - by bplus - 11-04-2023, 11:54 AM
RE: Indexed files - by SMcNeill - 11-04-2023, 12:42 PM
RE: Indexed files - by Dimster - 11-04-2023, 01:57 PM
RE: Indexed files - by bplus - 11-04-2023, 04:50 PM
RE: Indexed files - by Kernelpanic - 11-04-2023, 11:13 PM
RE: Indexed files - by PhilOfPerth - 11-05-2023, 12:21 AM
RE: Indexed files - by bplus - 11-05-2023, 01:55 PM
RE: Indexed files - by PhilOfPerth - 11-05-2023, 11:31 PM



Users browsing this thread: 1 Guest(s)