Active Forums => Programs => Topic started by: Dimster on June 14, 2021, 09:49:47 am
Title: Pseudo Random Access to Sequential Files
Post by: Dimster on June 14, 2021, 09:49:47 am
I am absolutely sure someone out there has done this before and likely better than the algorythm I'm placing here but it was just one of those AHA moments when Novarseg pointed out Seek #1,1 placed the pointer back to the beginning of a Sequential file. You have no idea how often I read that in the past and it never twigged to me that is was useful. I have been Opening and Closing the sequential files to get back to the beginning and the program slowed down so much it was ridiculous. I have just watched FellippeHeitor's recent video and he also points to Seek #1,1 as a useful tool in working with Sequential files.
So here is the simple program which appears to give Random Access to multiple Open Sequential files. The first thing to point out is, I had to convert the name of each sequential file to the same name and add a number to the end of the file name so I could open all 25 files quickly (or quicker than Opening all 25 with unique names one at a time). Then I have a loop there that captures the Last Record value for each of the 25 files. Helps with catching the End of File error but not necessary is you already know how many entries you have in your sequential files.
A true Random Access moves it's pointer forward and backward whereas this coding doesn't do that but gives the appearance that it does.