11-13-2023, 01:34 AM
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