+ Reply to Thread
Results 1 to 7 of 7

Lifetime and class modules

  1. #1
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58

    Lifetime and class modules

    Hi there,

    I need to have some object during all excel session. I have some class module and need to access the object of that. Now I have some trouble when using it - everytime I access the object the constructor is called each time and all old values/settings within the object are missed and even destructor is called after each access.

    I would need to declare it on the start and on the end only like that:

    Please Login or Register  to view this content.
    And then access it from VA modules like Global variable

    Please Login or Register  to view this content.
    I've tried to declare it as Static object inside procedure - still no work.

    Please Login or Register  to view this content.
    Any idea ? TIA
    ? ? ? I like the way how Excel can access system API. Really cool ! ? ? ?

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Declare a public variable, fixed_TCustom, in a normal module.
    Please Login or Register  to view this content.
    In the class module
    Please Login or Register  to view this content.
    (Or some other property of the class)

    This makes sure that fixedCustomObject always has the values that you want.

    I hope it helps.

  3. #3
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58
    Hi mikerickson,

    first of all THX for replay but I don't think it's the solution. Moreover this is not a correct OOP construction.

    What I need is to have object which is instanced only once on the Excel's start and available all the Excel's session time without any reinstancing.

    It should have something to do with Static word statement and a correct scope (and even maybe instancing of the module class too).

    Anyway THX for nfo !
    Last edited by bettatronic; 07-28-2007 at 05:46 PM.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    fixedCustomObject will be the first object instanced. Every time a new fixed_TCustom is instanced, the "value" of fixedCustomObject will be re-set (to the same "value") , but it will not create a new instance.

  5. #5
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58

    Thumbs up

    Sorry but I don't agree with you still. Your maybe work for constant but I need to have counter variable inside the class. Like this one:

    Class modules :: TCustom_Object

    Please Login or Register  to view this content.
    This is my class module. It's all about how to stay alive during full Excel's session. When Excel's terminating I want to show count variable of the object. That's all. But now everytime I call obj.proccess1 both constructor & destructor is called -> no old count status...

    Problem still persists but THX for your effort !

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I've tried similar things. I've declared a public objectCount variable in a normal module together with
    Please Login or Register  to view this content.
    The results have not been what I expected. I'm not sure if the counting technique flawed or my expectations are wrong.

    The technique in the previous posts was used to create a "null" for my class, but (as you noted) it's constant.

    Good luck with the problem.

  7. #7
    Registered User
    Join Date
    01-16-2007
    Location
    Near the box
    Posts
    58
    Just solved. Works great ! I'll provide my solution later.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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