[Gambas-user] Global multidimensional arrays

nando nando_f at ...951...
Sat May 7 17:45:19 CEST 2005


Same problem I encountered when I started using Gambas.
Here's what I did.

You cannot have what you want exactly.

You can do this...
At the top of a class or a module type...

PRIVATE my_array [5000,3000] AS FLOAT

This array is PRIVATE for the whole class or module.

-you can do PUBLIC non-arrays for a whole project but
 arrays can't be public for the whole project,
 only just a class or module.

Then make something like...
  PUBLIC SUB write_my_array (value as FLOAT,x AS INTEGER, y AS INTEGER )
    '--the pass in the value to write and match the my_array subscripts
  
    my_array [x,y] = value

  END

-you can use the above anywhere in your project like
  write_my_array (23.5, 4, 66)
  'which writes the value 23.5 into the array at [4,66]



Then make something like...
  PUBLIC SUB read_array (x AS INTEGER, y AS INTEGER)
    
    RETURN my_array [x,y]
  END

-you can use the above anywhere in your project like
   label1.text = read_array (4, 66)
   'which reads the value from [4, 66] and puts it in a label.


-Fernando



---------- Original Message -----------
From: ML <ml at ...973...>
To: gambas-user at lists.sourceforge.net
Sent: Sat, 07 May 2005 14:11:24 +0200
Subject: [Gambas-user] Global multidimensional arrays

> Hi all,
> 
> a few days ago I came across Gambas and the more I discover about it 
> the more I like it! Congratulations to all the developers for their 
> very neat, promising work!!!
> 
> Having started coding some test applications, I have a problem 
> though that I haven't been able to solve by trial and error and also 
> by looking at the documentation and in the ML. It could just be a 
> matter of poor experience and practice with Gambas but I have yet to 
> find a solution.
> 
> The problem is that I need to have a global bidimensional array of 
> floats, available through all modules and classes.
> 
> According to the help file,
> 
> "There is no such thing as a project-wide global variable in Gambas. 
> As a workaround, consider making a class called Global and declaring 
> your global variables as static public variables in that class, and 
> then referring to them as Global.variablename in your project. It's 
> still poor programming practice but at least they'll be identified 
> as global variables whenever you use them".
> 
> That's exactly what I've tried to do, but if I create a Global class 
> and declare in it a "static public P[5,5] as float", when trying to 
> compile the code, I get a "Arrays are forbidden here at line xx in 
> Global class" error.
> 
> So, if arrays are forbidden here, how can I overcome this problem?
> 
> TIA for your help,
> Piero
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: NEC IT Guy Games.
> Get your fingers limbered up and give it your best shot. 4 great 
> events, 4 opportunities to win big! Highest score wins.NEC IT Guy 
> Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list