In article <h5Sdnfwy9r41AXzbnZ2dnUVZ_gWdnZ2d@[EMAIL PROTECTED]
>,
"fripper" <fripper@[EMAIL PROTECTED]
> wrote:
> I am an absolute newbie to REALbasic ... having used VB for the past few
> years. Simple question .. how do I declare a variable that is then
> accessibl;e from all the Event handlers and Control routines? I see a
good
> bit about putting global functions/subs in a modules but how do I just
> declare a variable as global?
Same way as global functions/subs, but you click the "Add Property"
button instead of the "Add Method" one.
> An example would be helpful.
No problem:
1. Start a new project.
2. Click the Add Module button (or use the Project > Add submenu).
3. Double-click Module1 to open its editor.
4. Click the Add Property button.
5. Set its name to "gFoo" and its type to "String".
6. Click the global scope button (looks like a little globe).
Now, anywhere in your code, you can refer to it by name:
gFoo = "bar"
But note that this is generally considered bad form, for all the reasons
that global variables are considered evil. A somewhat better approach
would be to set its scope to Protected (the middle, yellow caution
icon), which still lets you access it anywhere, but only prefixed with
the module name:
Module1.gFoo = "Global variables suck!"
Of course you'd want to name Module1 something more descriptive. But
this lets you group your "global" data by topic, and avoids cluttering
the global namespace. It also makes it obvious, any time you're looking
at your code, exactly what "gFoo" is (i.e. a module or shared class
property, rather than a local variable or a global defined
who-knows-where).
Best,
- Joe
--
"Polywell" fusion -- an approach to nuclear fusion that might actually
work.
Learn more and discuss via:
<http://www.strout.net/info/science/polywell/>


|