L
laavista
What is the difference between a global and public variable?
Thanks, in advance, for your help.
Thanks, in advance, for your help.
laavista said:What is the difference between a global and public variable?
By a 'global' variable, we usually mean a public variable of unlimited scope
and lifetime.
When you state that they "place the controls" on an unbound form, do you use
a text box and name it, and because the hidden form would be part of a
"collection", the control name for the text box would be available to any
procedure?
If this correct, how do you specify the "type", e.g., long
integer?
You can just hold the
values in regular text controls, knowing that they are being set
and read by your code, so they'll have the correct values in them.
You can always use a format and decimal places so that date or
numeric values display correctly to you during development.
David W. Fenton said:For what it's worth, I don't do this. I don't use any global
variables directly, but only via functions (or class modules) that
are sure to return a valid value no matter what. I also don't use
globals for passing information between forms, as I believe that
introduces an insufficiently robust outside dependency. Again, I'll
tend to use a class module for that kind of thing.
I try to make my functions self-healing, which means using a static
variable inside the function and initializing it the first time the
function is called. The logic for assigning the variable will depend
on the type of value being returned. If it's the kind of value that
is initialized at startup and not changed, then it will be relooked
up from whereever the value is stored. If it's a different kind of
variable, the logic will be specific to its purpose.
Obviously, a static variable is not going to be used for the kind of
global that is used to communicate between parts of an application,
but I don't use those. That kind of variable belongs as a property
of a class module, with proper Let/Get methods.
Were I to use the form method as a way of avoiding any volatility of
values stored there, I would likely *still* wrap it in functions and
class modules, and use static variables where appropriate (so it
would look it up from the form only the first time it was called). I
don't write apps that need that kind of protection from volatility,
not because my apps are error-free and never ever experience a code
reset, but because my apps are built to not need any such values in
the first place.
Globals are a shortcut, seems to me, and a very bad one because
there is no interface to control how they are set. That's why I use
class modules, because then I have a standard interface for
controlling the values.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.