Ok, so if I have an array Dimmed (1 to 25) ..Dim MyArray(1 to 25) ...For I= 1 to 25:MyArray(I) = I +2: Next... and the program coding accesses a File and writes the entire array, closes, reopens and writes the entire array 10 more times. I would have 11 sequential writes to the same file carrying 25 pieces of data on each line.
I believe, in the case of MyArray, each element of the array would be 4 bytes. If I wanted to access only record #5 in the sequential file, then that record would start (25*4)*5 bytes away, correct???
So using Binary as the mode, to just extract that sequential record #5 would be
a$= ((Space$(4)*25)*5
get #1,,a$
Not quite....
DIM MyArray (1 TO 25) AS *whatever*
Now, before we can GET or PUT specific records, we need to know how large each record is. (RANDOM access files work the same way for us, btw.) To get the length, we just take the LENgth of *whatever*.
For example:
DIM MyArray (1 TO 25) AS LONG
L = LEN(MYArray(1)) ‘L is 4 here, as our type is a LONG. If we had an INTEGER, L would only be 2.
At this point, you can now open the file for binary access:
OPEN file$ FOR BINARY AS #1
And, to get the Nth record, it’s position is at (N - 1) * L +1.
So the first record: FirstRecordPosition = (1 - 1) * 4 + 1. (Or, at byte #1 for my LONG type array above.)
SecondRecordPosition = (2 -1) * 4 + 1 = 5
FifthRecordPosition = (5 -1) * 4 + 1 = 17
Now that you know how to calculate a record position, you just use it for the second parameter of your GET statement.
GET #FileHandle, (DesiredRecordNumber - 1) * RecordLength +1, RecordType
So, for the 5th record of the above, it’d be GET #1, 17, LongVariableType
.....
So if we DIM MyArray(1 TO 25) AS STRING * 11, we’d do the following to get the 5th record:
T$ = SPACE$(11)
GET #1, (5 - 1) * 11 + 1, T$
(Which breaks down to GET #1, 45, T$ to get the 11-byte string that starts at position #45 in the data.)