Re: What is common practice?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



It is a question of style, Jim, but I don't like globals because:

a) They lose their value when you reset your code, making them harder to debug.

b) You have to restart the application before any change gets to them.

c) There's always the problem of a local variable being clobbered by a global with the same name, and vice versa.

So my compromise is to read the value in the Load event of any form that depends on it.

BTW, I also prefer to store these configuration settings/values as records instead of fields in this table. This has the advantage of being more flexible (you can easily add more settings, just with another record), but the disadvantage that they are untyped (typically a Text (255) field, so you must validate if it is to store a date or number.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jim Franklin" <pleasedonotusethis@xxxxxxxxxxx> wrote in message
news:WzcIi.9055$gZ.7764@xxxxxxxxxxxxxxxxxxxxxxx

Just something I have often wondered, as it crops up with almost every application...

If you have a 1-record table which contains various settings for an application, and those settings are used frequently in different functions of the app, say via a function which opens the tbl_Settings recordset and returns the appropriate field, is it more common (and more efficient) to run the function every time a setting is needed, or to use a global variable, and use the function only once at startup to assign the variable value.

I know this isn't a 'Help! How do I...' question, but if anyone can answer this I would be very grateful,

Cheers,
Jim

.



Relevant Pages

  • Re: if not global -- then what?
    ... Such a thing is no different from keeping many global settings. ... shower all shared a single global temperature setting instead of having ... Python globals aren't as bad as in some other languages, ... if header is None: ...
    (comp.lang.python)
  • Re: Global Variables
    ... I have a global "set" structure for all the settings, ... I really don't see a better way than this - globals and all - although ... programming paradigm, rather than the more usual C imperative ... You are structuring your code as a set of state machines - C is just the syntax you use to write it. ...
    (comp.arch.embedded)
  • Re: Global Variables
    ... heavily on global variables. ... I have a global "set" structure for all the settings, ... All the state machines have access to all the settings and status ... I really don't see a better way than this - globals and all - although ...
    (comp.arch.embedded)
  • Re: Need help in Global variable in c
    ... how can I declare the global variable so that it can be set/get by ... you should avoid globals if possible. ... settings). ... The C language does not specify program behavior in ...
    (comp.lang.c)
  • Re: How do I save printer settings to a certain document?
    ... No version of Word has ever been able to store a printer ... Microsoft MVP (Word) ... printer settings when a document is saved wheras previous versions used to ... "Suzanne S. Barnhill" wrote: ...
    (microsoft.public.word.docmanagement)