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
#23
This thread seems to me have gone off the rails. The original question was whether arrays are possible within records. They aren't! But maybe there's a way to circumvent this limitation by "simulating" it.
I tried this, and it should come pretty close to arrays within records for certain programming tasks. I couldn't think of a better example.

Some data is requested, and then the answer is displayed, along with an image. Nice!  Big Grin

Code: (Select All)

'Verschachtelte Recordarrays - 7./10. Maerz 2026

Screen _NewImage(550, 390, 32)
$Color:32

Option _Explicit

Type Automodelle
  Modell As String
  Hubraum As String
  Leistung As String
End Type

Type Datenblatt
  Modelldaten As Automodelle
  Farbe As String
  FarbeBrilliant As String
  Verbrauch As String
  Tankgroesse As String
  Preis As String
End Type

Type Spezielles
  Extra As Datenblatt
  Sonderausstattung As String
End Type

Dim Modell(5) As Datenblatt
Dim Special(2) As Spezielles

Dim As String ps
Dim As Long Bild

Locate 2, 3
Input "Modell                : ", Modell(1).Modelldaten.Modell
Locate 3, 3
Input "Hubraum in ccm        : ", Modell(1).Modelldaten.Hubraum
Locate 4, 3
Input "Motorleistung Kw      : ", Modell(1).Modelldaten.Leistung
Locate 5, 3
Input "Farbauswahl            : ", Modell(1).Farbe
Locate 6, 3
Input "Farbe brilliant Ja/Nein: ", Special(1).Extra.FarbeBrilliant
Sleep 2

Cls
Locate 2, 3
Print "Ihre Auswahl war:"
Locate 4, 3
Print "Modell      : "; Modell(1).Modelldaten.Modell
Locate 5, 3
Print "Hubraum      : "; Modell(1).Modelldaten.Hubraum; " ccm"

Locate 6, 3
'KW auch als PS ausgeben
ps = Str$(Val(Modell(1).Modelldaten.Leistung) * 1.36)
Print "Motorleistung: "; Modell(1).Modelldaten.Leistung; " Kw"; " ("; ps; " PS )"

Locate 7, 3
Print "Farbauswahl  : "; Modell(1).Farbe

Locate 9, 3
If Special(1).Extra.FarbeBrilliant = "Ja" Then
  Modell(1).Preis = "52.899.00"
  Print "Preis Ihrer Modellauswahl: "; Modell(1).Preis
Else
  Modell(1).Preis = "49.500.00"
  Print "Preis Ihrer Modellauswahl: "; Modell(1).Preis
End If

Bild = _LoadImage("..\..\..\Bilder\AudiS3-Kl.jpg") 'Siehe Hinweis unten um das Bild zu erhalten
_PutImage (20, 185), Bild 'Platzierung des Bildes. Haengt von der Fenstergroesse ab

End

Image of the answer: "No" was entered.
[Image: Audi-Sportback-Record-Array.jpg]
Reply
#24
Would a functional 1D array within an array be enough to start with? It seems to work properly. I haven't tried higher versions yet. I'm just using all the available options. That's all. But this needs to be tested deeply, use would be at your own risk, it's not an official development branch, it's a modified version of 4.4.0 x86 and the tests were only done on Windows. Of course, I put this together with AI.

patched version: https://drive.google.com/file/d/1ueTungC...drive_link
was changed: https://drive.google.com/file/d/1YWAhFdz...drive_link
[Image: image.png]


Reply
#25
@Petr
access denied on first link
Reply
#26
@Jack access repaired, try again


Reply
#27
thank you Petr  Big Grin
off to testing
Reply
#28
Petr
this simple test run OK
Code: (Select All)

_Title "simple_test"

$Console:Only
_Dest _Console
Option _Explicit

Type mytype
    m( 10) As Long
End Type

Dim x As mytype
Dim As Long i

For i = 0 To 10
    x.m(i) = i
Next

For i = 0 To 10
    Print x.m(i)
Next

I am going to modify my decfloat stuff which uses arrays in udts a lot, so I can determine the performance and stability of your QB64, the modifications will take quite a bit of time but as soon as it's done and run some tests I will post the results here
Reply
#29
OK, I'll be glad. Now I'm already trying to extend to multi-element arrays in an array.

I also tried _Preserve operations (increase or decrease), GET, PUT, Erase, Redim. Everything behaved correctly.


Reply
#30
Can it do something like :
Code: (Select All)
_Title "simple_test"

$Console:Only
_Dest _Console
Option _Explicit

Type mytype
    m( 10) As Long
End Type

Dim x(10) As mytype
Dim As Long i,j
For j = 0 To 10
  For i = 0 To 10
    x(j).m(i) = i
  Next
Next
For j = 0 To 10
  For i = 0 To 10
    Print x(j).m(i)
  Next
Next
If so, that would be great. I've been hoping for that for years.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Arrays as UDTs Pete 26 1,245 02-06-2026, 04:31 AM
Last Post: bplus
  Preserving multi-dim arrays Pete 5 433 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,596 01-30-2025, 08:00 PM
Last Post: Pete
  C++ types > QB64 types: do we have an equivalent QB64PE page? madscijr 5 1,152 06-01-2024, 03:44 AM
Last Post: grymmjack

Forum Jump:


Users browsing this thread: 1 Guest(s)