Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDT problems
#22
(11-13-2023, 12:38 AM)eoredson Wrote: I need to know because I am using the following method to read/write a fixed length UDT array string to a random record in a file:

Code: (Select All)
' define an array as string.
Type Datatype
  Array As String * 16
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

Why go through such a complicated setup?   Why not just use an array directly?

Code: (Select All)
DIM DataRecord(1 TO 8) AS INTEGER

OPEN "datatest.dat" FOR RANDOM AS #1 LEN = 16
FOR j = 1 TO 10
    FOR l = 1 TO 8
        count = count + 1
        DataRecord(l) = count 'set the data
    NEXT
    PUT 1, j, DataRecord() '10 records from 1 to 80
NEXT

FOR l = 1 TO 8
    DataRecord(l) = 0 'clear the old data
NEXT

x = INT(RND * 10 + 1)
PRINT "Fetching record #"; x
PRINT "Which starts at"; (x - 1) * 8 + 1;
PRINT "and ends at"; x * 8
GET 1, x, DataRecord() 'get the random record

FOR i = 1 TO 8
    PRINT DataRecord(i) 'print the array
NEXT
Reply


Messages In This Thread
UDT problems - by eoredson - 11-12-2023, 05:46 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 05:49 AM
RE: UDT problems - by eoredson - 11-12-2023, 06:05 AM
RE: UDT problems - by mnrvovrfc - 11-12-2023, 06:33 AM
RE: UDT problems - by SpriggsySpriggs - 11-12-2023, 06:19 AM
RE: UDT problems - by eoredson - 11-12-2023, 06:42 AM
RE: UDT problems - by SMcNeill - 11-12-2023, 06:58 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 06:44 AM
RE: UDT problems - by eoredson - 11-12-2023, 06:50 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 06:57 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 06:54 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:02 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:09 AM
RE: UDT problems - by SMcNeill - 11-12-2023, 07:20 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:22 AM
RE: UDT problems - by TerryRitchie - 11-12-2023, 07:25 AM
RE: UDT problems - by SpriggsySpriggs - 11-12-2023, 07:27 AM
RE: UDT problems - by eoredson - 11-12-2023, 07:48 AM
RE: UDT problems - by justsomeguy - 11-12-2023, 11:06 AM
RE: UDT problems - by eoredson - 11-12-2023, 11:41 PM
RE: UDT problems - by eoredson - 11-13-2023, 12:38 AM
RE: UDT problems - by SMcNeill - 11-13-2023, 12:52 AM
RE: UDT problems - by justsomeguy - 11-13-2023, 12:58 AM
RE: UDT problems - by eoredson - 11-13-2023, 01:34 AM
RE: UDT problems - by SMcNeill - 11-13-2023, 02:34 AM
RE: UDT problems - by mnrvovrfc - 11-13-2023, 01:48 AM
RE: UDT problems - by eoredson - 11-13-2023, 01:59 AM
RE: UDT problems - by justsomeguy - 11-13-2023, 02:18 AM
RE: UDT problems - by eoredson - 11-13-2023, 02:26 AM
RE: UDT problems - by eoredson - 11-13-2023, 02:52 AM
RE: UDT problems - by justsomeguy - 11-13-2023, 04:57 AM
RE: UDT problems - by eoredson - 11-13-2023, 05:20 AM



Users browsing this thread: 1 Guest(s)