Hi,
I need to create an indexed array with at least 2 values (a string and an integer). But the documentation on “Array” states:
“Only one-dimensional arrays are supported by Array. Higher dimensional arrays can be populated via assignment statements…”
It’s not very clear for me, how to store 2 related values?
I have to store a string (the contents of a Listbox, line by line, via a loop) and an integer (Listbox.RowDepthAt(row)) and pass it all to a function.
Thanks
Something like this…
Dim myArray(-1, -1) As Integer
ReDim myArray(2, 2)
myArray(0, 0) = 5
myArray(0, 1) = 2
NOTE. You cannot mix types in an array so you can’t have a string and integer in the same array.
Solutions…
1.Use two arrays
2.Convert the integer into a string
3.Use an array of Pairs
4.Use an array of classes
Just for the sake of teaching a fast trick, but not saying that it is the best fit for whatever you need:
Var row() As Variant
row.Add Array(100, "a color", "blue")
row.Add Array(200, "a thing", "whatever")
Var column() As Variant = row(1) // get the second row
Var num As Integer = column(0) // 200
Var what As String = column(1) // a thing
Var value As String = column(2) // whatever
break
1 Like