Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002

    Unanswered: Global Public Variable or Dim variable in each form ?

    Which is better ?
    To set a public variable for use by any form that needs to use it, or to Dim a new variable in each form.

    What are the benefits or downsides to either?

    Anyone have any ideas ?

  2. #2
    Join Date
    Oct 2004
    Oxfordshire, UK
    ...memory overhead versus compiled file size. If the variable is declared in a form it is destroyed when the form is closed (the same argument applies with variables declared in a procedure) thus releasing the memory allocated to the variable. If you declare or search for the same variable in every form, the module file size increases.

    On the whole, it's easier to declare global variables as static variables in a public function and return the static variable, especially if you're referencing an application, system/API variable e.g. the current user name. You can code the function to only search for such variables once, but return the result many times...

  3. #3
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    Global vs. public depends on the use for the variable. If you're talking about an ADODB.connection object that your entire application uses, then yeah, go ahead and make that a global variable. However, if you're talking about making a variable global just because it gets used alot, like "i" for integer loops or "varItem" for collection iteration, well... that's not such a hot idea. It will be difficult to track what's changing who's values when unless the practical application warrants that type of behavior.

    So I guess the answer is, what do you need to use it for?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts