Results 1 to 3 of 3

Thread: GLOBAL VARIABLES for dummies

  1. #1

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    63

    Thumbs up

    I apologize if this info is redundant - I'm new here.

    It makes sense to name globals with a unique symbol/qualifier/etc so that others reading your code know the variable is global...something like g_CustomerName

    You can take this concept one step further by creating a type structure in a code module, and put all variables you want to be global in the structure...


    'Put all variables you want to be global in the type structure

    Type GlobalVariables
    InvoiceNumber as integer
    InvoiceDate as date
    CustomerID as string
    ...
    ...
    ... define all other globals here
    ...
    ...
    End Type

    'Now define a variable as the new structure

    Public g as GlobalVariables

    Now anytime you want to reference a global variable, just type g.(variable name) like...

    g.InvoiceNumber = 12345
    g.InvoiceDate = now()

    and so on and so on. What's nice is that anytime you type g. to reference a global, the menu appears with all the variables. Now you don't have to memorize exactly what you called each variable. You can just select it from the list.

    I'm not sure how this method effects efficiency.

    Peace


  2. #2
    Guest
    Hello,

    Neet idea, I'll give it a try.

    Best,

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    That's what you're "supposed" to do, it's a good tip, you should technicly do it with a class module rather than a type though, then you can put verification code on your variables.

Posting Permissions

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



Click Here to Expand Forum to Full Width