Array of arrays in xojo, or the lack thereof

I understand xojo does not have the ability to do directly an array of arrays.

I have also seen one can do something of the like with a variant, which I would prefer to avoid (so it seems)

that left me with something else I read that uses a class to mimic this.

having looked about for any working example I am left stuck not having a clue, therefore can anyone just give me a little example I might be able to paste into my IDE and play about with to get the concept in mind.

Thank You in advance.

Array of arrays? :face_with_raised_eyebrow: You can make multidimentional arrays:

Var arrayName(size ,size2,...sizeN) As dataType

What do you need an Array of arrays for? Thinking of that sounds like you need another data structure. Arrays or dictionaries of classes…

But, if you really really want an Arrays of Arrays it is posible with xojo, the only catch is that arrays need to have a DataType and the Variant is the one that can have Arrays. What is the problem with having an array as Variant?

Dim a ( ) As Integer = Array (1, 2, 3)
Dim b ( ) As Integer = Array (4, 5, 6)
Dim c ( ) As Integer = Array (7, 8, 9)

Dim x ( ) As Variant

x.AddRow a
x.AddRow b
x.AddRow c

If what you want is a way to access the contents, you will need to make a reference to the array first. to avoid making an extra reference each time by hand, you can use a method that extends the Variant:

Public Function Item(Extends x as Variant, Item as integer) as integer
  Dim z ( ) As Integer = x
  Dim i As Integer = z (item)
  Return i
End Function

With this, at the end of the first example you can write:

Dim i As Integer = x (1).Item (1)

And i will be 5

I had a situation where i needed that because the “elements” could have significantly different number of members so a multidimensional array was not an option, and I did not want the overhead of variants… so I created a class with methods/operator converts to imitate the functionality and most of the syntax of an array… Works OK

BUT IMO Xojo should support arrays of arrays. Not doing that means a lot more overhead and coding than should be needed.

-Karen

class myArray
dim contents() as string
end class

dim superArray() as myArray

2 Likes

While not complex , not quite that simple either if you want the object level to have an array like API… Which I did.

Karen

Thanks for the input everyone.

the solution is with DaveS which I have tried and it works for the simple needs I had.
although since using the method I realized I could do it a different array using one array and a very quick sort on the dat in the array.

but now I know how to use a class in a different way than I did before so all good!