[AccessD] Global Vars (was Ambiguous Name)

jwcolby jwcolby at colbyconsulting.com
Thu Sep 22 21:31:29 CDT 2011


 > The only advantage I see to the wrapper is that you get to set a breakpoint.

A little more help that that.  You can add code that logs the change and the time of day, the 
workstation running the code or whatever you can think of that might help you troubleshoot the issue.

You can add code that limits the values that can go into the variable.  Perhaps the global is a date 
and the date should never be before D day, but somehow it is being set to the date of black friday. 
  Perhaps it is a currency and should never be negative.  Perhaps it is a long that should only be 
between 1000 and 10000.  Perhaps it is a date that must always be between two other date variables.

Properties exist because they allow you to do validations.  Today (when you define the global 
variable) you cannot imagine that you would ever need such a thing, yet in six months you see six 
very good reasons.

Properties can be read-only (from outside of the module) or write only (from outside of the module). 
  Globals are just a variable that anyone can set at any time for any reason.

I have lots of "globals" which can be set from inside of the module but only read from outside 
(through a property).  These are "global" in that anything anywhere can read them, but not write them.

There are lots of programmers that have thousands of variables that are global, everything in sight. 
  There are others that have a dozen carefully selected.  I have a dozen, carefully selected, but I 
do in fact have a dozen or so.  I use a lot of class and module private variables in the header area 
(global to the class or module).

The simple truth is that no variable should have scope beyond what is needed for that variable. 
Scope exists for a reason.  Global would not exist if it were not occasionally necessary.  Module 
and class "global" (private in the header of the module and class) exist because they are needed. 
They are still global but only to that module or class.  If it were good practice to make everything 
global then having private keywords would be unnecessary.

John W. Colby
www.ColbyConsulting.com

On 9/22/2011 6:40 PM, Kenneth Ismert wrote:
>> Drew Wutka:
>> ...
>> So, even if you wrap your global variables inside of a
>> class, you are still scoping an instance of that class
>> globally, which makes it a global variable...
>
> My point exactly. The 'globals are bad' camp haven't explained how a code
> wrapper that lets you change the value makes the global problem go away.
>
> And yes, there are common situations in Access where you want changeable
> global values.
>
> The only advantage I see to the wrapper is that you get to set a breakpoint.
> Little help when it fails in the field.
>
> -Ken



More information about the AccessD mailing list