Page 1 of 1

Array of lists

Posted: Sat Jan 06, 2024 4:29 am
by tua
How does one define an array of lists when the size of the array is only known @ runtime?

Re: Array of lists

Posted: Sat Jan 06, 2024 4:38 am
by jacdelad

Code: Select all

Structure Lists
  MyListDefinition.l
EndStructure

Define NewMap ListMap.Lists()

Debug @ListMap("List1")
Debug @ListMap("List2")
One of many solutions. Each map element contains a list with the definition of your choice.

Re: Array of lists

Posted: Sat Jan 06, 2024 5:38 am
by AZJIO
I didn't understand the question, but I made an example with an array of lists.
What do you want to define?

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
Next

Re: Array of lists

Posted: Sat Jan 06, 2024 11:09 am
by Demivec
tua 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())
Does that answer your question? The example can be extended to populate the example lists and display their contents if it is needed.

Re: Array of lists

Posted: Sat Jan 06, 2024 5:38 pm
by tua
thanks to all - exactly what I was looking for