+ Reply to Thread
Results 1 to 12 of 12

Class Newbie question #2 - Check if Class already loaded/set?

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Class Newbie question #2 - Check if Class already loaded/set?

    I am creating my first class and it will be possible for the Class Initialize event to fire twice.

    Is there any way to check if the Class is already "loaded" (I'm not sure I'm using the right terminology here)?
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    Is it possible to "unload" the class after its usage to avoid "double loading"?

    Set "ClassName" = Nothing


    Or, declare a public variable (e.g. KKK) that when the class is initialized first time, you give kkk a value (e.g. 999). then, before trying to re-initialize it, check the value of kkk: if it is 999, do not initialize, else, initialize.
    Does it make sense?
    Click on the star if you think I helped you

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    Quote Originally Posted by adyteo View Post
    Is it possible to "unload" the class after its usage to avoid "double loading"?

    Set "ClassName" = Nothing
    Unfortunately no. I need to avoid ending the class at that point.


    Quote Originally Posted by adyteo View Post
    Or, declare a public variable (e.g. KKK) that when the class is initialized first time, you give kkk a value (e.g. 999). then, before trying to re-initialize it, check the value of kkk: if it is 999, do not initialize, else, initialize.
    Does it make sense?
    Yes it does make sense. I'd prefer to avoid adding global variables. Guess it can't be helped.

    Thanks for your help +1

  4. #4
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    thanks for the +

    if you find a method to check whether the class has already been initialized, post it here. we all learn something new every day

  5. #5
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    As a class must be 'loaded' into an object (as far as I understand, although happy to be corrected), could you use:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-28-2012
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    187

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    Did it work?

  7. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    Quote Originally Posted by TKCZBW View Post
    As a class must be 'loaded' into an object (as far as I understand, although happy to be corrected), could you use:

    Please Login or Register  to view this content.
    It sounded good and I thought it would work. "Compile error: Invalid use of object"

    P.S. you are right that a class is an object. I didn't know but I checked. VarType(classname) = 9 (9 = vbObject)

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    What did you actually try as code - I assume you didn't use Object as a variable.

    A class is not an object - an instance of a class is. Typically you would store this in a variable which you can indeed test to see if it's Nothing.
    Remember what the dormouse said
    Feed your head

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    Quote Originally Posted by romperstomper View Post
    What did you actually try as code - I assume you didn't use Object as a variable.

    A class is not an object - an instance of a class is. Typically you would store this in a variable which you can indeed test to see if it's Nothing.
    Hi Rory, Class is unknown territory to me.

    Below is what I tried.

    Please Login or Register  to view this content.

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    You need Is Nothing, not = Nothing.

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    Quote Originally Posted by romperstomper View Post
    You need Is Nothing, not = Nothing.
    Of course! What was I thinking?!?

    Thanks Rory

  12. #12
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Class Newbie question #2 - Check if Class already loaded/set?

    Quote Originally Posted by mc84excel View Post
    What was I thinking?
    I've yet to figure that out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Class Newbie question #1 - Non Event procedures overhead
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-29-2014, 05:27 AM
  2. [SOLVED] Newbie-ish Class Module Sub Question
    By zaimor in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-07-2013, 10:48 AM
  3. class foactory cannt supply requested class
    By rakeshkaduskar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2012, 02:00 PM
  4. [SOLVED] ComboBox class .AddItem filled in class module
    By Jacques Grobler in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-03-2012, 05:48 AM
  5. Class and one property is also a class or collection
    By gosa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2011, 05:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1