ObjoBasic doesn’t currently support Xojo-style multidimensional array declarations like:
Var MyArray(-1, -1) As String
That syntax is specific to Xojo’s built-in multidimensional arrays. ObjoBasic’s array model is deliberately a little different: arrays are generic, dynamic, zero-based objects, and multidimensional data is represented as an array of arrays.
So for a 2D array/grid you would write:
Var grid As Array(Of Array(Of Integer)) = [[1, 2], [3, 4]]
Print(grid[0][1]) # 2
Print(grid[1][0]) # 3
The access pattern is:
grid[row][column]
not:
grid(row, column)
The reason for this design is that it keeps arrays consistent with the rest of ObjoBasic’s object model. A “2D array” is still just normal arrays containing normal arrays, so the usual array methods, typing rules, and iteration behaviour all still apply. It also allows ragged arrays naturally, where different rows can have different lengths.
That said, your question showed that the ergonomics and discoverability could be better, especially for users coming from Xojo. I’ve made some improvements for the next release:
Var grid As Array(Of Array(Of String)) = Array.Grid(Of String)(3, 4, "")
grid[1][2] = "Hello"
Print(grid[1][2]) # Hello
Array.Grid(rows, columns, defaultValue) creates a rectangular array of arrays with independent row arrays, so appending/resizing one row won’t accidentally affect the others.
I’ve also improved the compiler error for Var MyArray(-1, -1) so it now explains the ObjoBasic equivalent instead of just failing with a generic parser error.
https://feedback.objo.dev/feature/378