Thread safe ListBox values Help!

I need to update an application I did with an old version of RealBasic which used extensively threads, and most of them accessed the UI directly. I solved most of the issues using the Task class provided in one of the sample xojo projects but there is something I haven’t been able to figure out:

In my thread I access the values of the listbox. Something like:

// add all listbox values //
  for row = 1 to myListBox.ListCount-1
    for col = 1 to 4
          sum = sum + val(myListBox.cell(row,col)
    next
  next

Because I am not supposed to access the listbox directly from the thread, I think I must copy all values into a multidimensional array or something like that. My first thought was to have a global multidimensional array and update the array when the listbox changes. Then in the thread use the valued of the array.
The problem is that the number of rows of the listbox is not fixed, so I can’t declare the array with a fixed number of elements. I think there is nothing similar to a push() method for multidimensional arrays.

Any idea on how can I solve this problem? (I don’t care if I use arrays or any other workaround, but I need to have access to the listbox values from within a thread).

Can you ReDim the array each time you go to fill it from the ListBox? If you ReDim it, you can use the row and column count as the new dimensions.

You really don’t need to know the number of elements up front. Just Redim myArray(-1) at the start and use myArray.append to add each item. When all appending is finished Ubound will give you the number of elements in the array.

Oh. I did not know something like Redim existed. That is going to help… Thanks!

Harrie, I believe that the ‘append’ method does not work with multidimensional arrays. I’ll use Dale’s solution.