11-04-2023, 01:57 PM
Hi Phil
Back on the old site I had a similar discussion with Steve on a project I was trying to get off the ground. I recall the topic we were using was called "Random Access to a Sequential File". The major stumbling block was finding a particular record in a sequential file. The first thing I remember Steve pointing out is that it can't be done accurately without knowing the length of each record. It's easy to determine the size of each variable within a record (ie a Long = 4 byte and an Integer = 2 etc). The challenge is the string variables. Back then Steve pointed out that the safest was to determine what the words were in the longest string and to be sure to pad with spaces those string words which were less than the longest.
If you have another way to calculate the exact length of each string's length, then you wouldn't need any spacing.
It is a simple matter then of opening the file once and use Seek #1 (or Seek #100 whatever the file number you have chosen to open) to position the search at the beginning of the sequential file, Record 1 would be record 1 (ie Seek #1, 1). If memory services me right, the pointer finding the records will always end on the last data item so to get to the next record you have to add one (assuming you want the next record)
The way the random access worked, and I'm struggling with my memory here - say you started with search for record 22, then it was Seek #1,(record length *21+1). and the next search was for record 14, you would reset the search back to the beginning and do the same thing (Seek #1,1 to get back to the beginning) then Seek #1,(record length *14+1)
Sorry Phil if this is not what you were thinking of, and of course if I'm way out to lunch on the structural layout of the coding.
Back on the old site I had a similar discussion with Steve on a project I was trying to get off the ground. I recall the topic we were using was called "Random Access to a Sequential File". The major stumbling block was finding a particular record in a sequential file. The first thing I remember Steve pointing out is that it can't be done accurately without knowing the length of each record. It's easy to determine the size of each variable within a record (ie a Long = 4 byte and an Integer = 2 etc). The challenge is the string variables. Back then Steve pointed out that the safest was to determine what the words were in the longest string and to be sure to pad with spaces those string words which were less than the longest.
If you have another way to calculate the exact length of each string's length, then you wouldn't need any spacing.
It is a simple matter then of opening the file once and use Seek #1 (or Seek #100 whatever the file number you have chosen to open) to position the search at the beginning of the sequential file, Record 1 would be record 1 (ie Seek #1, 1). If memory services me right, the pointer finding the records will always end on the last data item so to get to the next record you have to add one (assuming you want the next record)
The way the random access worked, and I'm struggling with my memory here - say you started with search for record 22, then it was Seek #1,(record length *21+1). and the next search was for record 14, you would reset the search back to the beginning and do the same thing (Seek #1,1 to get back to the beginning) then Seek #1,(record length *14+1)
Sorry Phil if this is not what you were thinking of, and of course if I'm way out to lunch on the structural layout of the coding.