Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrays inside Types?
#21
I adapted GROK's suggestion https://grok.com/share/c2hhcmQtMg_564536...04ca64c554
Code: (Select All)

Type MyType
    s As String * 80
End Type

Dim MyVar As MyType
Dim mBlock As _MEM: mBlock = _Mem(MyVar)

Dim As Long i

For i = 0 To 9
    PutDouble mBlock, i, Sqr(i + 1)
Next

For i = 0 To 9
    Print GetDouble#(mBlock, i)
Next

_MemFree mBlock

' Helper to make syntax nicer
Sub PutDouble (mem As _MEM, index As Long, value As Double)
    _MemPut mem, mem.OFFSET + index * 8, value
End Sub

Function GetDouble#(mem As _MEM, index As Long)
    Dim v As Double
    _MemGet mem, mem.OFFSET + index * 8, v
    GetDouble# = v
End Function

still way too messy
Reply
#22
Example of using a UDT to hold a string of Str$(numbers), actaully x,y locations stored in sequence of x y x y x y...

Code: (Select All)
Type Mask
    xys As String
End Type

Screen _NewImage(1024, 200, 32): _ScreenMove 100, 60
Cls , &HFF000000
Print "Hello World!"

Dim hello As Mask
nolight~& = Point(0, 15)
For y = 0 To 20
    For x = 0 To 12 * 8
        If Point(x, y) <> nolight~& Then hello.xys = hello.xys + Str$(x) + Str$(y)
    Next
Next
Print "Press any to continue... zzz"
Sleep
ReDim msk(0) As String
Split hello.xys, " ", msk()
Cls
i = 0
While i < UBound(msk) - 2
    For r = 0 To 10
        Line (10 * Val(msk(i + 1)) + 40, 10 * Val(msk(i + 2)) + 10)-Step(r + 3.5, r + 3.5), _RGB32(255 - r ^ .8 * 25), B
    Next
    i = i + 2
Wend

Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
    Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
    curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
    dpos = InStr(curpos, SplitMeString, delim)
    Do Until dpos = 0
        loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
        arrpos = arrpos + 1
        If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
        curpos = dpos + LD
        dpos = InStr(curpos, SplitMeString, delim)
    Loop
    loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
    ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
End Sub

Pretty cool print job too!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Arrays as UDTs Pete 26 1,244 02-06-2026, 04:31 AM
Last Post: bplus
  Preserving multi-dim arrays Pete 5 430 12-19-2025, 03:17 PM
Last Post: Dimster
  Array out of passing arrays... Pete 2 417 09-22-2025, 08:53 PM
Last Post: ahenry3068
  Methods in types bobalooie 7 1,591 01-30-2025, 08:00 PM
Last Post: Pete
  C++ types > QB64 types: do we have an equivalent QB64PE page? madscijr 5 1,148 06-01-2024, 03:44 AM
Last Post: grymmjack

Forum Jump:


Users browsing this thread: 1 Guest(s)