Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 23rd, 2003, 04:24 PM
lonewolf32 lonewolf32 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 52 lonewolf32 User rank is Corporal (100 - 500 Reputation Level)lonewolf32 User rank is Corporal (100 - 500 Reputation Level)lonewolf32 User rank is Corporal (100 - 500 Reputation Level)lonewolf32 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 7 h 4 m 43 sec
Reputation 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

Reply With Quote
  #2  
Old April 24th, 2003, 02:41 PM
defjamninja defjamninja is offline
Overly white
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Fresno, CA
Posts: 83 defjamninja User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
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.

Reply With Quote
  #3  
Old April 24th, 2003, 02:46 PM
lonewolf32 lonewolf32 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 52 lonewolf32 User rank is Corporal (100 - 500 Reputation Level)lonewolf32 User rank is Corporal (100 - 500 Reputation Level)lonewolf32 User rank is Corporal (100 - 500 Reputation Level)lonewolf32 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 7 h 4 m 43 sec
Reputation 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,

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Question about Initialize event

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap