I can’t do anything with a constant here, because I cannot declare it from integers. And I never heard of the number datatype (cannot find it in the docs either).
I tried this:
Dim encoded(-1) As Byte
But I encounter a OutOfBoundException, I don’t know why, because I thought -1 meant variable length.
All arrays in Xojo are of variable length. Dim arr(-1) As Byte means the same as Dim arr() As Byte. It is an empty array.
Resize an array as Ramon mentioned above with ReDim.
As all arrays are of variable length, you can always use Append, Insert and Remove even when you have set a size at declaration:
Dim arr(3) As Byte
arr.Append(98)
> arr will contain 0, 0, 0, 0, 98
Now:
Dim encoded(-1) As Byte
encoded(0) = 123 // I encounter a OutOfBoundException
So now you know why: because it is an empty array.
This will work:
Dim encoded(-1) As Byte
encoded.Append(123)
And this too:
Dim encoded(-1) As Byte
ReDim encoded(0) // instead of 0 there could also be a (possibly complex) calculation
encoded(0) = 123