Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Basic Realbasic > Re: Global Vari...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 7 Topic 3257 of 3321
Post > Topic >>

Re: Global Variabldz

by Joe Strout <joe@[EMAIL PROTECTED] > Sep 7, 2007 at 01:44 PM

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/>
 




 7 Posts in Topic:
Global Variabldz
"fripper" <f  2007-09-07 14:47:07 
Re: Global Variabldz
Joe Strout <joe@[EMAIL  2007-09-07 13:44:03 
Re: Global Variabldz
Anic <sans@[EMAIL PROT  2007-09-07 22:35:15 
Re: Global Variabldz
"fripper" <f  2007-09-07 17:50:57 
Re: Global Variabldz
Joe Strout <joe@[EMAIL  2007-09-07 16:39:56 
Re: Global Variabldz
befr@[EMAIL PROTECTED] (  2007-09-10 16:55:19 
Re: Global Variabldz
Joe Strout <joe@[EMAIL  2007-09-10 10:57:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 22:47:07 CDT 2008.