#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    52
    Rep Power
    12

    Question about Initialize event


    If I instantiate a class, what is the proper way to terminate the class if I decide I don't want that object to be loaded? Here is an example of what I'm talking about:
    Code:
    Private Sub Class_Initialize()
    Dim ret As Boolean
    Dim reason As String
    Dim swLock As New SoftwareLock
    
        ret = swLock.IsLicenseValid(reason)
        If ret = False Then
            MsgBox reason
            ' Terminate class?
            Exit Function
        End If
        
        Set swLock = Nothing
    
    End Sub
    But I have read in the VB docs that you are not supposed to interact with the user in the Initialize and Terminate events. Also how would you terminate a object from within its Initialize event anyway? But there are many methods inside the class that the user could call first. Would I have to put this code in each method? Or is there a better way to do this?

    Thanks!
    Dave
  2. #2
  3. No Profile Picture
    Overly white
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Fresno, CA
    Posts
    83
    Rep Power
    12
    How about you create a read only property that stores the value you want to check. Then have the app check the value and display the messagebox. You could also check the value inside the class at the start of any methods, exit the method and return an error the value is false.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    52
    Rep Power
    12
    Thanks for the suggestions. I pretty much did the second thing you suggested, keeping a private boolean and checking it at the beginning of every method in the class. (I set the boolean during the Initialize event). It seems to be working great.

    Thanks again,
    Dave

IMN logo majestic logo threadwatch logo seochat tools logo