ArrayList bidimensional?

serge

Member
Licensed User
Hello,

Somebody knows if an ArrayList could be bi-dimensional?, or if i have a structure like this:

Dim Type(X,Y) ElementList(0)

How could i redim this array?

Thanks!
 

serge

Member
Licensed User
it worked, thx... and, could you tell me how i could redim (add or delete elemenst to the array) without lossing the current data?

Thanks again!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to manually copy the data each time.
Something like:
B4X:
Sub Globals
    'Declare the global variables here.
    Dim Type(x,y) ElementList(0)
    Dim Type(x,y) TempList(0)
End Sub

Sub App_Start
    'usage example
    Redim(10)
    For i = 0 To 9
        ElementList(i).x = i
        ElementList(i).y = i * 2
    Next
    Redim(100)
    Msgbox(ElementList(5).x,ElementList(4).y)
End Sub

Sub Redim(size)
    Dim TempList(size,2)
    For i = 0 To ArrayLen(ElementList())-1
        TempList(i).x = ElementList(i).x
        TempList(i).y = ElementList(i).y
    Next
    ElementList() = TempList() 'Both arrays will point to the same array.
End Sub
Don't call this method periodically. Instead set the array size to be larger than what you currently need (at least twice the size).
 
Top