02-24-2026, 12:43 AM
I've been trying to build a small utility to create a Random Access file from an existing text file, and had a few problems getting it to work.
I have an alpha- sorted, single-element text file, and need to do a binary search to find words within it. I have got this to work , but found, after experimenting, that the Len for the file needed to be at least 2 bytes longer than the max data size. I could find no information about this in the Wiki, and reckon R/A files deserve their own spot there. Here's a (very simple) prog that demonstrates the problem, with the added 2 bytes.
I have an alpha- sorted, single-element text file, and need to do a binary search to find words within it. I have got this to work , but found, after experimenting, that the Len for the file needed to be at least 2 bytes longer than the max data size. I could find no information about this in the Wiki, and reckon R/A files deserve their own spot there. Here's a (very simple) prog that demonstrates the problem, with the added 2 bytes.
Code: (Select All)
SW = 1040: SH = 720
Screen _NewImage(SW, SH, 32)
SetFont: F& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", 20, "monospace"): _Font F&
_ScreenMove (_DesktopWidth - SW) / 2, 90
Print "Aim: to convert a serial text file"
Print "(single element, various lengths, alpha-sorted)"
Print "to Direct access (Random access) file."
Print: Print "Problem: Record length"
'prepare a dummy Sequential list
Restore
Data "ARMY","BREAKFAST","CONCORDE","DANGER","ENERGY","FABCDEFGHIJKLMN"
Dim Wrd$(6): For a = 1 To 6: Read Wrd$(a): Next
'name the R/A file
RandFile$ = "RandFile.dat"
'get longest data length 10, length of FLASHPOINT
Input "Max Data length"; MaxLength
RL = MaxLength + 2 ' Len needs to be extended by 2 bytes
RecNum = 0
'prepare R/A file
Open RandFile$ For Random As #1 Len = RL
' Read each word and write to random file
For a = 1 To 6: Put #1, a, Wrd$(a): Next
Close
' Verify the random access file
Print: Print "Reading records from random access file:"
Open RandFile$ For Random As #1 Len = RL
For a = 1 To 6
Get #1, a, wrd$: Print wrd$; " ";
Next
End
Sleep
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) 
Please visit my Website at: http://oldendayskids.blogspot.com/

Please visit my Website at: http://oldendayskids.blogspot.com/

