Android Question Can't get array of panels to work...

Jason Wood

Member
Licensed User
I've looked at other posts on here and my code is similar, so I don't know why it doesn't work.

B4X:
Sub Globals
    ...
    Private targetList(10) As Panel
End Sub



Sub generateTargetMatrix(noOfTargets As Int)
    ...
    Dim targetCounter As Int
    targetCounter = 1
   
    For y = 1 To rowCount
        For x = 1 To rowCount
           
            targetList.(targetCounter).Initialize("targetMulti")  <<<< ERROR line 356
            targetList.(targetCounter).Color = Colors.ARGB(255,102,102,102)
            targetList.(targetCounter).Enabled = False
            targetList.(targetCounter).Elevation = 10dip
            pnlGame.AddView(targetList.(targetCounter), (x * gutterWidth) + ((x - 1) * targetWidth), offsetTop + ((y - 1) * (targetWidth + gutterWidth)), targetWidth, targetWidth)
            targetCounter = targetCounter + 1
        Next
    Next
End Sub

I create a panel array in Sub Globals, the later when trying to work with the array a compile error is produced:

B4X:
Error description: Only 'Length' is supported by arrays.
Occurred on line: 356

What I need to achieve is to have an array or list of Panels. If this array was called panelList for example, I want to be able to access it like:

panelList(1).Visible = False
panelList(2).Enabled = True
... etc

I've tried lots of ways but can't get it to work!
 

Cableguy

Expert
Licensed User
Longtime User
B4X:
            targetList(targetCounter).Initialize("targetMulti")
            targetList(targetCounter).Color = Colors.ARGB(255,102,102,102)
            targetList(targetCounter).Enabled = False
            targetList(targetCounter).Elevation = 10dip
            pnlGame.AddView(targetList(targetCounter), (x * gutterWidth) + ((x - 1) * targetWidth), offsetTop + ((y - 1) * (targetWidth + gutterWidth)), targetWidth, targetWidth)
            targetCounter = targetCounter + 1
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
1 error
B4X:
For y = 1 To rowCount ' Error ColCount
    For x = 1 To rowCount

2 error
B4X:
targetList.(targetCounter).Initialize("targetMulti") ' Dot after tergetList is wrong
targetList(targetCounter).Initialize("targetMulti") ' this is right
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
Y = 0 to rowcount - 1
targetCounter = 0 to 9
 
Upvote 0
Top