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.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  More info about Random Access files PhilOfPerth 28 962 02-25-2026, 01:50 PM
Last Post: ahenry3068
  Embedding and Extracting MANY files ! ahenry3068 20 1,560 11-15-2025, 10:19 AM
Last Post: ahenry3068
  program that stitches together a bunch of image files into one giant poster? madscijr 15 2,388 10-24-2024, 06:08 PM
Last Post: madscijr
  Linux HTTP WEB Server Issues - Large Files Fail old_coder 0 463 03-27-2024, 08:33 PM
Last Post: old_coder
  Making the content list of files inside a Zip ? euklides 13 2,407 02-08-2024, 03:52 PM
Last Post: euklides

Forum Jump:


Users browsing this thread: 1 Guest(s)