[AccessD] Global Variable

John W. Colby jwcolby at colbyconsulting.com
Tue May 17 12:09:43 CDT 2005


I am a bit confused.  I just use public and private, I don't use global.  In
my mind Public just means Global.  Do Public and Global have different
impacts on the ability to see the variable depending on where the viewing
code is or where the variable is?  Global can only be used in a module
header correct?  And Public can only be used in a module or class header.
Are you saying that Global used in a class header is not visible outside of
the class?

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of MartyConnelly
Sent: Tuesday, May 17, 2005 12:51 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Global Variable


Just to clarify something from the mysts of tyme.
A variable defined with the GLOBAL keyword is available to any code in any
module in your project. All code sees and sets the same data. This is
essentially a VB 3.0 method and the PUBLIC keyword which was introduced in
VB 4.0 is generally preferred over GLOBAL. The PUBLIC keyword introduced in
VB4 and VB5 allowed you to create a 
module-level
variable that can still be accessed by code in other modules.
I believe the use of "Global" in a code module is more descriptive than 
"Public";
 the Public keyword has two meanings: in a BAS code module.
It means Global any in any other module type.
Using Public in forms and classes makes sense but in BAS modules the use of
Global immediately identifies the scope without having to back up and check
what module type you are in. 

This really goes back further than the mysts of time into the early 
paeolithic.

Fortran II had a global common area for variables, Fortran IV had a 
labelled global common area.
These were used for a variety of reasons, old Fortran guys hated keypunching
long  subroutine calls with about 40 variables, it also saved memory as 
you could
equivalence common areas, so if you had requirements for 2 (1000,1000) 
arrays
you could map the same memory area to them. This method was used in 
Cobol and PL1
and algol. However you had to be very careful with the order and type of 
variables in a common area.
This has declarative changes in Fortran 90 and 95 but by then they had 
take out the computed GOTO, *sob*


Gustav Brock wrote:

>Hi John
>
>Well, here we have full control on where functions put their nasty 
>fingers.
>
>I haven't managed yet to build self generating code; to some this would 
>indicate a brave new world, to some it would be a nightmare - functions 
>creeping around and attacking our globals and eating our children... 
>gosh. But worse, they would soon learn how to take advantage of your 
>functions to change those "private variables"! Be prepared.
>
>/gustav
>
>  
>
>>>>jwcolby at colbyconsulting.com 05/16 10:58 pm >>>
>>>>        
>>>>
>
>..  Making this a global allows functions
>that have no business setting these variables to change them.  By 
>having a private variable returned by a public function, any function 
>that needs the
>information can get it but cannot modify it.
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada



-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com






More information about the AccessD mailing list