> This looks like a 'Many to One' problem.
> You want all the Doors to raise an event - and to identify which Door
> it is.
> If you have a Class then you can only set one instance of that Class
> into One 'Dim WithEvents MyDoor' Template.
> The way Controls do this is by being Control Arrays - so you get an
> Index passed in - at that point one is off.
> You could make each Door a UserControl - and have a control array of
> user controls.
> Alternatively you could have a Class that 'Fronts' the Doors and pass
> the actual object over in the event.
> I have knocked up an example of this - One Form, Two Classes :-
> ============== FORM1.FRM =================
> Option Explicit
> Dim WithEvents DoorMgr As clsDoorMgr
> Dim Door1 As New clsDoor
> ' --- FORM1 - Add Three Command Buttons
> Dim Door2 As New clsDoor
> Private Sub Command1_Click()
> Static AllDoors As New clsDoorMgr
> Set DoorMgr = AllDoors
> End Sub
> Private Sub Command2_Click()
> DoorMgr.RegisterDoor Door1
> Door1.Name = "Door One"
> DoorMgr.RegisterDoor Door2
> Door2.Name = "Door Two"
> End Sub
> Private Sub Command3_Click()
> Door1.DoorOpen
> Door2.DoorOpen
> End Sub
> Private Sub DoorMgr_DoorIsOpened(D As clsDoor)
> MsgBox "Door is Open " + D.Name
> End Sub
> Private Sub Form_Initialize()
> Command1.Caption = "Initialize DoorMgr"
> Command2.Caption = "Register Doors"
> Command3.Caption = "Open Doors"
> End Sub
> ========================================
> ' --- clsDoorMgr.cls
> Option Explicit
> Public Event DoorIsOpened(D As clsDoor)
> Sub RegisterDoor(D As clsDoor)
> Set D.Parent = Me
> End Sub
> Public Sub DoorIsOpened(D As clsDoor)
> RaiseEvent DoorIsOpened(D)
> End Sub
> ========================================
> ' --- clsDoor.cls
> Option Explicit
> Public Event DoorIsOpened(D As clsDoor, V$)
> Private mParent As clsDoorMgr, _
> mName As String
> Public Property Set Parent(Value As clsDoorMgr)
> Set mParent = Value
> End Property
> Public Property Let Name(Value$)
> mName = Value
> End Property
> Public Property Get Name$()
> Name = mName
> End Property
> Public Sub DoorOpen()
> Call mParent.DoorIsOpened(Me)
> End Sub
> =======================================
> Quite an interesting exercize -
> =======================================
> On Tue, 20 Aug 2002 00:36:22 -0500, "Mike Schilling"
> >Does anyone know of some type of routine to respond to events of
objects in
> >a collection.
> >For example:
> >-objDoor is an object which has an "Opened" event
> >-colDoors is a collection of objDoor objects
> >To repond to the event with just an object, you would code:
> >Sub objDoor_Opened()
> >'code when door has opened
> >'yadda yadda yadda
> >End Sub
> >But what if there were several - or several hundred - objDoor "items"
> >(objects) in an objDoors collection, and one of them doors opened.
How would
> >you respond to that?
Sent via Deja.com http://www.deja.com/