[Gambas-user] array declaration versus referencing array elements

Doriano Blengino doriano.blengino at ...1909...
Wed Dec 16 06:57:39 CET 2009


kevinfishburne ha scritto:
> I have some code:
>
> PUBLIC myarray AS String[10000, 2]
> ...
> myarray[x, 0] = stuff
> myarray[x, 1] = morestuff
> myarray[x, 2] = evenmorestuff
>
> and receive an "out of bounds" error message when referencing the third
> array element assignment (myarray[x, 2] = evenmorestuff).
>
> I can only assume that the array declaration defines the total number of
> elements and that referencing the array elements starts at zero. In other
> possibly more confusing words:
>
> PUBLIC myarray AS String[10000, 2] = 10000x2 total elements
>
> and
>
> myarray[x,y] = myarray[0-9999,0-1]
>
> I think my confusion may have come from my old VB6 days with "OPTION BASE"
> and all that crapola. Someone please confirm that GAMBAS works as I
> speculated or let me know if I'm missing something. Thanks all.
>
>   
I think you posed a question and replied to it by yourself... :-)

The upper bound, 2 in this case, declares the number of elements, as in 
C, and those elements are numbered from 0 to 1. This idea is common in 
many other places; for example, all .Count properties say how many 
elements are in the object (columns in a gridview, elements in a 
collection...), but you address those elements from 0 to Count-1.

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list