Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indexed files
#4
Here's another demo, it's loading a Random Access file with "fake" data for practice reading and writing.
Code: (Select All)
_Title "UDT to Random Access File Test" ' b+ 2021-12-24
Type Image
    As String * 255 Text, FileName
    As Long SzX, SzY, PosX, PosY
End Type

Const SW = 1000, SH = 700
ReDim As Image TheItem(1 To 100), TheRecord

TheItem(1).Text = FakeText$(255)
TheItem(1).FileName = FakeText$(255)
Print TheItem(1).Text
Print Len(TheItem(1).Text)
Print TheItem(1).FileName
Print Len(TheItem(1).FileName)
Print "zzz"
Sleep

'make fake data to file
For i = 1 To 100
    TheItem(i).Text = FakeText$(255)
    TheItem(i).SzX = 100 + Rnd * 20
    TheItem(i).SzY = 70 + Rnd * 14
    TheItem(i).PosX = Rnd * (SW - TheItem(i).SzX)
    TheItem(i).PosY = Rnd * (SH - TheItem(i).SzY)
    TheItem(i).FileName = FakeText$(255)
Next

Open "Data Dump.RA" For Random As #1 Len = Len(TheRecord)
For i = 1 To 100
    'odious and tedious is this
    TheRecord.Text = TheItem(i).Text
    TheRecord.SzX = TheItem(i).SzX
    TheRecord.SzY = TheItem(i).SzY
    TheRecord.PosX = TheItem(i).PosX
    TheRecord.PosY = TheItem(i).PosY
    TheRecord.FileName = TheItem(i).FileName
    Put #1, , TheRecord
Next
Close #1
Print "Data File Ready"

' OK we got data filed! Now can we get it back
Open "Data Dump.RA" For Random As #1 Len = Len(TheRecord)
For i = 1 To 100
    Cls
    Get #1, i, TheRecord
    Print "Record Number:"; i
    Print "Text: "; TheRecord.Text
    Print "SzX:"; TheRecord.SzX
    Print "SzY:"; TheRecord.SzY
    Print "PosX:"; TheRecord.PosX
    Print "PosY:"; TheRecord.PosY
    Print "FileName:"; TheRecord.FileName
    Print " zzz..."
    Sleep
Next
Close #1

Function FakeText$ (lengthh)
    BlankString$ = Space$(lengthh)
    fini = Int(Rnd * 255) + 1
    For i = 1 To fini
        Mid$(BlankString$, i, 1) = Chr$(Rnd * (96 - 32) + 32)
    Next
    FakeText$ = BlankString$
End Function
b = b + ...
Reply


Messages In This Thread
Indexed files - by PhilOfPerth - 11-03-2023, 11:21 PM
RE: Indexed files - by a740g - 11-03-2023, 11:40 PM
RE: Indexed files - by bplus - 11-03-2023, 11:44 PM
RE: Indexed files - by bplus - 11-03-2023, 11:50 PM
RE: Indexed files - by TerryRitchie - 11-03-2023, 11:55 PM
RE: Indexed files - by bplus - 11-03-2023, 11:55 PM
RE: Indexed files - by SMcNeill - 11-04-2023, 12:29 AM
RE: Indexed files - by bplus - 11-03-2023, 11:57 PM
RE: Indexed files - by JamesAlexander - 11-04-2023, 01:20 AM
RE: Indexed files - by PhilOfPerth - 11-04-2023, 01:39 AM
RE: Indexed files - by mnrvovrfc - 11-04-2023, 02:21 AM
RE: Indexed files - by PhilOfPerth - 11-04-2023, 07:44 AM
RE: Indexed files - by bplus - 11-04-2023, 11:54 AM
RE: Indexed files - by SMcNeill - 11-04-2023, 12:42 PM
RE: Indexed files - by Dimster - 11-04-2023, 01:57 PM
RE: Indexed files - by bplus - 11-04-2023, 04:50 PM
RE: Indexed files - by Kernelpanic - 11-04-2023, 11:13 PM
RE: Indexed files - by PhilOfPerth - 11-05-2023, 12:21 AM
RE: Indexed files - by bplus - 11-05-2023, 01:55 PM
RE: Indexed files - by PhilOfPerth - 11-05-2023, 11:31 PM



Users browsing this thread: 1 Guest(s)