[Gambas-user] Something i do not understand
Tobias Boege
taboege at ...626...
Mon Dec 8 17:44:07 CET 2014
On Mon, 08 Dec 2014, Fabien Bodard wrote:
> Dim grad As Float[][][]
>
> grad = New Float[][width, height]
> grad[x][y] = [0.2, 0.2]
>
> give me a 'bad number of dimention error' .. why ????
>
The syntax
Float[][width, height]
does not exist in Gambas. Multi-dimensional arrays are only implemented
for native datatypes (Float, etc.), not for classes like Float[]. Even if
it was implemented, Float[][A, B] would still yield a 2-dimensional array
of Float[] objects whereas Float[][][] would be a 1-d array of Float[][]
objects. Those two things are different / incompatible.
If you want to use
Dim grad As Float[][][]
you must do
grad = New Float[][][](size1) ' size1 so that x < size1
grad[x] = New Float[][](size2) ' size2 so that y < size2
grad[x][y] = [0.2, 0.2]
See attached script.
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
#!/usr/bin/gbs3
Public Sub Main()
Dim grad As Float[][][]
Dim x, y As Integer
x = 2
y = 1
' Ensure that no "out of bounds" is raised
grad = New Float[][][](x + 1)
grad[x] = New Float[][](y + 1)
grad[x][y] = [0.2, 0.2]
End
More information about the User
mailing list