Each record for a Random Access file must be exactly the Len spec'd in Open statement
for strings you must use fixed length strings
Dim as String * some number! (not a variable)
for strings you must use fixed length strings
Dim as String * some number! (not a variable)
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."
'measure the length of words use length of longest
Restore
Data "ARMY","BREAKFAST","CONCORDE","DANGER","ENERGY","F23456789012345"
Maxlength = 0
Dim Wrd$(6)
For a = 1 To 6:
Read Wrd$(a):
If Len(Wrd$(a)) > Maxlength Then Maxlength = Len(Wrd$(a))
Next
Print Maxlength ' = 15
Dim record As String * 15 ' <<< a number not a variable required for fixed strings
' random access needs fixed record lengths must use fixed strings for records
'name the R/A file
RandFile$ = "RandFile.dat"
'prepare R/A file
Open RandFile$ For Random As #1 Len = 15
' Read each record and write to random file
For i = 1 To 6
record = Wrd$(i)
Put #1, i, record
Next
Close
' Verify the random access file
Print: Print "Reading records from random access file:"
Open RandFile$ For Random As #1 Len = Maxlength
For i = 1 To 6
Get #1, i, record: Print record
Next
End
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever

