April 23rd, 2003, 05:24 PM
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:
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?
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
' Terminate class?
Set swLock = Nothing
April 24th, 2003, 03:41 PM
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.
April 24th, 2003, 03:46 PM
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.