Results 1 to 3 of 3

Thread: [RESOLVED] User Defined Classes and Collections - Event Procedures

Threaded View

  1. #1

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Resolved [RESOLVED] User Defined Classes and Collections - Event Procedures

    Is it possible to call an event procedure based on the value of a property in a user defined class?

    I have a class "MyUser" and an associated collection "MyUsers". The MyUser object has a Boolean property call "Active".
    What I would like to do is call an Event Proc (UserActivate) in the collection class, whenever an instance MyUser has its Active property set to TRUE that sets all the Active property of all other instances of MyUser in MyUsers to FALSE.

    I currently have a sub that checks for this, but I need to call it any time something changes in the active instance of MyUsers. I would like to have this fire automatically any time the property changes.


    Code snippets attached:
    VB Code:
    1. 'From the MyUser Class Module
    2. Private pActive As Boolean
    3.  
    4. Public Property Get Active() As Boolean
    5.     Active = pActive
    6. End Property
    7.  
    8. Public Property Let Active(iActive As Boolean)
    9.     pActive = iActive
    10. End Property
    11.  
    12.  
    13. 'From the MyUsers Class Module
    14. Private pMyUsers As Collection
    15.  
    16. Public Function Add(FullName As String, EMail As String, Active As Boolean)
    17. Dim NewUser As MyUser
    18. Dim Key As Variant
    19.  
    20.     With NewUser
    21.         .FullName = FullName
    22.         .EMail = EMail
    23.         .Active = Active
    24.         Key = .FullName
    25.     End With
    26.    
    27.     ' add to the private collection
    28.     pMyUsers.Add NewUser, Key
    29.     Set Add = NewUser
    30.    
    31. Function_Exit:
    32.     Set NewUser = Nothing
    33. End Function
    34.  
    35.  
    36. 'The following snipped are from my regular modules
    37.  
    38. 'Object vailables used throughout my code
    39. Dim TestUsers As MyUsers
    40. Dim TestUser As MyUser
    41.  
    42. ' This is the sub I call repeatedly to change the active flag on all users other than the active user
    43. Sub ChangeActive(ActiveUser As MyUser)
    44. Dim OtherUser As MyUser
    45.     For Each OtherUser In TestUsers
    46.         If OtherUser.FullName <> ActiveUser.FullName Then
    47.             OtherUser.Active = False
    48.         End If
    49.  
    50. Set OtherUser = Nothing
    51. End Sub
    Last edited by DKenny; Sep 19th, 2005 at 04:30 PM.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width