DWUTKA at marlow.com
DWUTKA at marlow.com
Mon May 16 16:03:12 CDT 2005
I concur. Drew -----Original Message----- From: Ken Ismert [mailto:KIsmert at TexasSystems.com] Sent: Monday, May 16, 2005 3:12 PM To: 'Access Developers discussion and problem solving' Subject: RE: [AccessD] Global Variable Globals are appropriate if the data they store is truly global in scope. So, things like Application Name and Current Login Name are proper candidates for globals. Problems can happen when data that is really local to some smaller context, like a form or report, is made global for programming convenience. This can quickly become the Acme "Shoot Yourself in the Foot" kit that Charlotte warns about: you start fighting synchronization issues (keeping local and global data consistent), other code changing your "local" global when you least expect it, dependencies on objects that may or may not be open and active, etc. Ideally, the data holder (the object with the local data) should TELL the foreign object what it needs to do its work. The foreign object shouldn't have to ASK or ASSUME. With a tell-style of data passing, synchronization becomes a non-issue, because the foreign object is given only what it needs to do its next task. Other code or objects not party to the conversation can't interfere by unexpectedly changing data. Lastly, this style of decoupled data passing allows the foreign object to be driven by any data holder, enhancing flexibility and reducing dependencies. Unfortunately, Access does all it can to encourage bad programming practice (case in point: the [Forms]![Form]![Control] syntax, a classic "ask" construct). And it's "tell" constructs, like OpenArgs, are insufficient for any but the simplest data passing needs. Most veteran programmers, through hard experience, grasp this issue and come up with better data passing schemes to work around it. Still, there seems to be no commonly accepted way to "do it right", and it remains a stumbling block for the novice. -Ken -----Original Message----- From: Charlotte Foust [mailto:cfoust at infostatsystems.com] Sent: Monday, May 16, 2005 11:58 AM To: Access Developers discussion and problem solving Subject: RE: [AccessD] Global Variable Now, Gustav, you know there are no guarantees for "nice" code, regardless. It's just easier to write bad code if you lard it with globals, which is why it is frowned upon by so many of us who prefer to avoid shooting ourselves in the foot. Charlotte Foust -----Original Message----- From: Gustav Brock [mailto:Gustav at cactus.dk] Sent: Monday, May 16, 2005 9:34 AM To: accessd at databaseadvisors.com Subject: RE: [AccessD] Global Variable Hi John You may like or prefer or need, or not, a global variable - that's up to everyone to decide for him/herself - but they are not "bad practice", not even in general. You may write clumsy code using globals, but not using them gives no guarantee for nice code. /gustav >>> jwcolby at colbyconsulting.com 05/16 5:00 pm >>> To dimension a global variable just go to the header of any module and type in Global MyVar as SomeVarType That's all there is to it, you can now reference the variable from any code in the project. Don't get carried away with them, they are considered bad practice in general. 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 Joe Rojas Sent: Monday, May 16, 2005 10:54 AM To: 'Access Developers discussion and problem solving' Subject: [AccessD] Global Variable Hi All, I am using a code example, from Microsoft, that allows me to print a constant number of lines on a report. The code example uses a variable that is defined as Global. "Global TotCount As Integer" What's the deal with Global? I can't find it defined anywhere. TIA! JR -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com