|
Post by bplus on Dec 10, 2023 19:29:02 GMT -5
_Title "Simple Random Access demo" ' bplus 2023-12-10
Type RecordType recNum As Long comment As String * 50 End Type
'Make a record: Dim Shared Record As RecordType, lenRecord&, nRecs& lenRecord& = Len(Record)
' start up a new data file If _FileExists("Simple Random Data.dat") Then Kill "Simple Random Data.dat" Open "Simple Random Data.dat" For Random As #1 Len = lenRecord&
'Store a 10 records: For i = 1 To 10 Record.recNum = i Record.comment = "This is record #" + _Trim$(Str$(i)) Put #1, i, Record Next
' check records nRecs = LOF(1) / lenRecord& Print "number recs:"; nRecs ' good 1 lets get it For i = 1 To nRecs Get #1, i, Record Print Record.recNum; ","; Record.comment Next Print " First 10 records starts the file." Print "We will add some more at every other record starting at 11." Print "zzz press any... " Sleep _KeyClear ' add more records For i = 11 To 20 Step 2 Record.recNum = i Record.comment = "This is record #" + _Trim$(Str$(i)) Put #1, i, Record Next Print "Every other record added from 11 to 19," Print "zzz press any to see the file now... " Sleep Cls
' Final check records nRecs = LOF(1) / lenRecord& Print "number recs:"; nRecs ' good 1 lets get it For i = 1 To nRecs Get #1, i, Record Print Record.recNum; ","; Record.comment Next
Close #1
|
|