Array of lists
Posted: Sat Jan 06, 2024 4:29 am
How does one define an array of lists when the size of the array is only known @ runtime?
Code: Select all
Structure Lists
MyListDefinition.l
EndStructure
Define NewMap ListMap.Lists()
Debug @ListMap("List1")
Debug @ListMap("List2")
Code: Select all
EnableExplicit
Structure y
List x.i()
EndStructure
Define Dim Arr.y(0)
Define i
AddElement(Arr(0)\x())
Arr(0)\x() = 1
AddElement(Arr(0)\x())
Arr(0)\x() = 2
ReDim Arr(1)
AddElement(Arr(1)\x())
Arr(1)\x() = 11
AddElement(Arr(1)\x())
Arr(1)\x() = 22
For i = 0 To ArraySize(Arr())
ForEach Arr(i)\x()
Debug Arr(i)\x()
Next
Nexttua wrote: Sat Jan 06, 2024 4:29 am How does one define an array of lists when the size of the array is only known @ runtime?
Code: Select all
Structure item_list
List items.s()
EndStructure
Define lists_needed
lists_needed = Random(12, 1) ;number of lists defined at runtime
Dim b.item_list(lists_needed - 1) ;zero based size
Debug ArraySize(b())
Repeat:
lists_needed = Random(12, 1) ; change number of lists defined at runtime
Until lists_needed <> ArraySize(b() + 1)
ReDim b.item_list(lists_needed - 1) ;or Dim b.item_list(lists_needed) to clear / free all previously existing lists
Debug ArraySize(b())