+ Reply to Thread
Results 1 to 7 of 7

Lifetime and class modules

Hybrid View

  1. #1
    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

    
    Private p_sheet As Worksheet
    Private p_left as Integer
    Public count As Integer
    
    Private Sub Class_Initialize()
              ' constructor
               count = 0
    End Sub
    
    Private Sub Class_Terminate()
               ' destructor
    End Sub
    
    Public Property Let left(vdata As Integer)
             p_left = vdata
    End Property
    
    Public Sub proccess1()
             ....                         ' some code here
             count = count + 1
    End Sub
    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 !
    ? ? ? 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
    I've tried similar things. I've declared a public objectCount variable in a normal module together with
    Private Sub Class_Initialize()
    objectCount = objectCount + 1
    End Sub
    
    Private Sub Class_Terminate()
    objectCount = objectCount - 1
    End Sub
    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.

  3. #3
    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