11-13-2023, 02:34 AM
(11-13-2023, 01:34 AM)eoredson Wrote:Quote:Why go through such a complicated setup? Why not just use an array directly?Because I might have more stuff in the UDT in addition to a single array:
Code: (Select All)' define an array as string.
Type Datatype
Array As String * 16
Var As Integer
Array2 As String * 16
Var2 As Integer
Array3 As String * 16
Var3 As Integer
End Type
Dim DataRecord As Datatype
Dim Array(8) As Integer
Open "datatest.dat" For Random As #1 Len = Len(DataRecord)
' store array.
For L = 1 To 8
Array(L) = L
Next
' put array into UDT string.
For L = 1 To 8
Mid$(DataRecord.Array, (L - 1) * 2 + 1, 2) = MKI$(Array(L))
Next
' put 10 records into file.
For X = 1 To 10
Put 1, X, DataRecord
Next
' get random record from file.
X = Int(Rnd * 10 + 1)
Get 1, X, DataRecord
' get array from UDT string.
For L = 1 To 8
M = CVI(Mid$(DataRecord.Array, (L - 1) * 2 + 1, 2))
Print M;
Next
End
Wouldn't this still be easier to just use Array1, Array2, Array3 and Var1, Var2, Var3 naturally? Just swap over to BINARY instead of RANDOM and read each array/variable as needed. Their position is still going to be set in stone and easy to calculate. ((record - 1) * 54 + 1) is the position of the first array record in the data. The other arrays are just offset by 18, if you ever need to get them individually.