ArrayList bidimensional?

Discussion in 'Questions (Windows Mobile)' started by serge, Jul 16, 2008.

  1. serge

    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!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    ArrayLists can only have one dimension.
    You can redim this array with"
    Code:
    Dim ElementList(10,2'10 - new size, 2 - number of fields.
     
  3. serge

    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!
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You will need to manually copy the data each time.
    Something like:
    Code:
    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).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice