[Gambas-user] Global multidimensional arrays
Eilert
eilert-sprachen at ...221...
Mon May 9 11:28:21 CEST 2005
Hi Piero,
>
> The problem is that I need to have a global bidimensional array of floats,
> available through all modules and classes.
Well, the question of global or not is very easy to solve: You can have
global variables and arrays by declaring them PUBLIC and then calling
them with the name of the module/class they are in
(any_class.my_global_string) from any other class/module.
This works with standard 1-dimensional arrays too. I need a lot of
string arrays. My way of using this in my current project is to store
the strings of dimension 2 as part-strings in the array of dimension 1,
separated with chr$(9) or so. To extract the single part-strings, I use
Split(). This works rather fast, so no problem for me.
With float arrays you might use another trick: create dimension 1 as an
object array - myArray as Object[] - and place as many float arrays in
it as are needed for that dimension. The float arrays then represent
dimension 2. Access is possible via two square brackets. Here is a small
example within one class:
PRIVATE abc AS NEW Object[]
PUBLIC SUB _New()
DIM xyz AS Float[]
DIM i AS INTEGER
FOR i = 0 to 9
xyz = NEW Float[]
xyz.Resize(10)
abc.Add(xyz)
NEXT
Now you access the 2 dimensions for example by
abc[i][j] = something
Hope it helps!
Rolf
More information about the User
mailing list