473,785 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Globals and system instability

DFS
Not sure whether it's bad programming practice or not, but I have a module
of globals I declare in each system:

Global ws As Workspace
Global db As Database
Global td As TableDef
Global rs As Recordset, rs1 As Recordset
Global rs2 As Recordset, rs3 As Recordset
Global ctl As Control
Global frm As Form, subFrm As Form
Global rpt As Report
Global qItem As QueryDef
Global menuObject As Object

Most of them get used in each Access app, so I don't feel bad about
instantiating them this way. Saves some development time and hassles.

In general:
* I Set the db object to CurrentDB when opening forms, and never Close it.
* I always Set and Close the recordset objects I use.
* I Set the frm references as necessary, but never reset them to Nothing.

I'm wondering if declaring and using Global objects this way contributes to
system instability? When my apps reach a certain arbitrarily large size
(lots of forms and code), I always, always get the dreaded corruption
screen.

Usually it's recoverable, but sometimes not. And it always causes me to
curse.

Thoughts?

Nov 13 '05 #1
2 1654
I am not aware of the approach causing instability in terms of ms-access.

However, use of global as a general rule is frowned upon. It makes the code
less modular, generally harder to debug, and harder to maintain.

Further, it also tends to make the programming process harder, as you have
to ensure that no other code is using those variables. If other code needs
those variables at the same time, then you are toast. So, it may not make
your application less stable, but it is sure fire way to introduce hard to
find bugs, and increase general maintaining costs, and simply increases the
difficulty in moving code from on application to another.

Even worse, is what about importing and using other code? If you get name
conflicts, then again confusion arises.

Global variables should ONLY be used for things that need to be global. So,
for example, you do not want to use global to pass variables between forms
(besides, you can set a reference to the other form, and use any variables,
or procedures in that form anyway - so, you don't even have to pass
vars...just references the previous form).

So, yes, as general approach to software and programming, global are much
frowned upon. And, the approach makes your code MUCH MUCH less modular. If
you take only ONE of those routines, then all the global have to follow
(and, you got to figure out what global must be moved, and you got to go
find those global).

Further, how can you have two routines operating at the same time? If you
got global, then you can only have ONE routine that users the "ctl"
(control) variable at a given time. Really, next to impossible to maintain
such systems.

When a developer working for me brings code with UNNECESSARY globals, I send
the code back with instructions to remove them....
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #2
DFS
Albert D. Kallal wrote:
I am not aware of the approach causing instability in terms of
ms-access.
OK. Something is causing me mucho corruption, and it seems haphazard, but
I'm almost sure it's related to a module, as the .mdb will corrupt when I
try to compile a module, or load a form that uses a module.

It's very frustrating.
However, use of global as a general rule is frowned upon. It makes
the code less modular, generally harder to debug, and harder to
maintain.

Further, it also tends to make the programming process harder, as you
have to ensure that no other code is using those variables. If other
code needs those variables at the same time, then you are toast.
Nah. Just create another global, and increment it with a number...:)

So,
it may not make your application less stable, but it is sure fire way
to introduce hard to find bugs, and increase general maintaining
costs, and simply increases the difficulty in moving code from on
application to another.

Even worse, is what about importing and using other code? If you get
name conflicts, then again confusion arises.

Global variables should ONLY be used for things that need to be
global. So, for example, you do not want to use global to pass
variables between forms (besides, you can set a reference to the
other form, and use any variables, or procedures in that form anyway
- so, you don't even have to pass vars...just references the previous
form).
I use two "types" of globals: 1) Access objects as I listed in my original
post, and 2) a few string variables like cSQL (for character SQL statement).

I do mostly use form references to get things like ID values from tables.
But to reference the form itself, I often set and use a global called 'frm'.
But I never Set frm = Nothing. That was the point of my post: does
declaring and setting but not closing a variety of Globals introduce
instability? I would think not, but something's hammering my systems.
So, yes, as general approach to software and programming, global are
much frowned upon. And, the approach makes your code MUCH MUCH less
modular. If you take only ONE of those routines, then all the global
have to follow (and, you got to figure out what global must be moved,
and you got to go find those global).
Sure. So I start each new Access system I create with a standard set of
modules :

- General Declarations (includes the Globals)
- routines to manipulate Access objects
- routines related to file dialogs and browser
- things related to startup (disable built-in toolbars, etc)

A bit of it goes unused, but it's not much code.
Further, how can you have two routines operating at the same time? If
you got global, then you can only have ONE routine that users the
"ctl" (control) variable at a given time.
It's rare - next to never - that I need two routines to be running together.
If one is nested inside another, obviously I use Globals ctl1 and ctl2, etc.
Really, next to impossible
to maintain such systems.
It hasn't been a problem for me over the last 5-8 years. But in the past
year or so, I'm getting frequent corruptions whenever my Access projects get
large. I haven't been able to resolve it, and it takes too much time to
recreate the same system without the use of the globals. If that's what it
is.
When a developer working for me brings code with UNNECESSARY globals,
I send the code back with instructions to remove them....


Unnecessary is the key word. I like the judicious use of globals, but I may
try to reduce them as a test.

Thanks for the reply, Albert.

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2840
by: Frostillicus | last post by:
I'm trying to use array_multisort to sort by one of the dimensions of an array stored in $GLOBALS like this: array_multisort($GLOBALS, SORT_STRING, SORT_DESC); Each "row" in $GLOBALS contains a value for 'href', 'desc', and 'info' but when I try to pass one of these "columns" to array_multisort() it whinges about it not being an array or a sort value :-( Can PHP not understand arrays stored in $GLOBALS or something?
7
1761
by: John | last post by:
Hi, I'm looking for the best way to deal with globals in PHP. As a 'C' software developer, I would normally avoid all globals and not have any at all, but use structs and pass everything in the function parameters... However, being realistic, I can see that globals can (and do ?) have a place in PHP web scripts.
45
2684
by: It's me | last post by:
I am new to the Python language. How do I do something like this: I know that a = 3 y = "a" print eval(y)
11
2858
by: Matt | last post by:
Hello, I'm rather new to C++ and have a question about globals. What is the big deal about them? They make things much easier to program because you don't have to worry about all the passing back and forth between functions. And, if you are going to give the reason about "it makes it easier to debug your program if you don't use globals" well to that I say, how so? Yes, not using globals prevents a random function from setting...
1
2118
by: gianguz | last post by:
In the following example Global is able to create and manage access to objects of any kind (even in a multithreading environment) with and index value attached to. So a Global<0, string> is a unique string instance object allocated into the system that can be accessed from any point into the program simply 'creating' another instance of Global<int, T> with the same id and type.Like globals, destruction of these objects is delegated until...
8
1915
by: Michael Wild | last post by:
Hi all I'm not quite new to PHP, but also not very proficient in its use, so please excuse me if my question is a FAQ. Perhaps I didn't know the right terms, but google wasn't my friend this time :-) I had a page running on a host which worked perfectly fine. Then, one day, it stopped working since strangly some values in the $GLOBALS array are not set. For example things such as $GLOBALS, $GLOBALS,
2
3110
by: xml0x1a | last post by:
How do I use exec? Python 2.4.3 ---- from math import * G = 1 def d(): L = 1 exec "def f(x): return L + log(G) " in globals(), locals() f(1)
5
1294
by: Steven W. Orr | last post by:
I have two seperate modules doing factory stuff which each have the similar function2: In the ds101 module, def DS101CLASS(mname,data): cname = mname+'DS101' msg_class = globals() msg = msg_class(data) return msg
1
1857
by: cokofreedom | last post by:
if __name__ == '__main__': print "Globals (For Loop):" try: for i in globals(): print "\t%s" % i except RuntimeError: print "Only some globals() printed\n" else: print "All globals() printed\n"
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.