Xojo and Arrays

Hi all,

I’m working on a project and decided to use array.pop and array.push but everytime i try to compile to test some code i get the following error:

“This Item does not exist: userSelectedCells.push Grid(x,y)”

for context here’s the entire method:

Sub SelectCell(x As Integer, y As Integer)
  if selectedCount < 10 then
    dim wasSelected As Boolean = false
    dim selectedItem as Integer = -1
    for i as integer = 0 to (selectedCount - 1)
      if Grid(x,y) = userSelectedCells(i) then
        wasSelected = true
        selectedItem = i
        
        exit for
      end if
    next
    
    Grid(x,y).userSelected = not wasSelected
    
    if  wasSelected = false then
      userSelectedCells.push Grid(x, y) // this is where i'm getting the error.
      selectedCount = selectedCount + 1
    else
      userSelectedCells.remove selectedItem
      selectedCount = selectedCount - 1 
    end if
    
  end if
End Sub

userSelectedCells is a protected property of the class, and is defined as follows:

Protected userSelectedCells(-1) As GridCell

Any and all help would be appreciated.

Thanks and regards.

AFAIK, there is no Array.push() method in Xojo… You should try Array.Append().

Wow… I dont know why I had it in my head that there was a push method… I could have swore I saw it in the language reference… LONG week. Thanks =)

You have Append and Insert to get things into the array. Pop removes the last element and Remove lets you specify the index. Full list of Array functions are at Page Not Found — Xojo documentation