Results 1 to 4 of 4

Thread: I thought they were global

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    158

    I thought they were global

    I have a sub that defines a new collection. I then attempt to add an item to it within a function and it craps out complaining about the object not being defined. I thought that once an object was defined it was accessable to everything.

    Any ideas what's wrong?

    Everso

  2. #2
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    It depends upon how you define it. The only way to make a variable (object or otherwise) avaialble to everything in your program is to use the Public key word in a module.

    VB Code:
    1. 'In a module
    2.  
    3. 'Available to everything
    4. Public MyCollection As Collection
    5.  
    6. 'Available to everything in this module
    7. 'But not other forms or modules
    8. Private MyCollection As Collection

    {EDIT} It must be defined in the declarations section of the module. Defining it in a sub or function in a mdoule does not work.

    Greg
    Last edited by gdebacker; Jan 5th, 2002 at 04:40 PM.
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  3. #3
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    You can create an object in a sub and then pass a reference to a function in another module without the object being public.

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    158
    Thanks. I'll go have a play. I was hoping to avoid a module because it allways seems silly having a module with only a declaration in it

    Everso

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