Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
Example:
Public objClass as Class
'Events
Public Event StartMakingClass ()
Public Event FinishedMakingClass ()
Public Sub New()
RaiseEvent StartMakingClass ()
'Do some stuff, may take a while
RaiseEvent FinishedMakingClass ()
End Sub
End Class
Public Class objClassCollection
Private mobjClasses as New System.Collection.ArrayList
Default Public Property objClassClasses (Index as Integer) as objClass
Get
Return CType(mobjClasses(Index), objClass)
End Get
Set(ByVal Value As objClass)
mobjClasses(Index) = Value
End Set
End Property
Public Sub New()
For x as int16 = 1 to 100
Dim aobjClass as New objClass
mobjClass.Add(aobjClass)
Next x
End Sub
End Class
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
If I remember correctly, dotnet supports the ability to define parameterized constructors -- that is, when instantiating an object, you can pass a parameter to it which can be utilized by the constructor (as opposed to VB6, which requires that the object be instantiated before you can pass anything into it).
If that is correct, then you could do something like this:
1. In objClassCollection, define "callback" procedures for your two events that accept an objClass argument:
(VB6 syntax)
Public Sub StartMakingClass(Obj As objClass)
End Sub
Public Sub FinishedMakingClass(Obj As objClass)
End Sub
2. In objClass, create a parameterized constructor that accepts an objClassCollection argument:
(I have no idea what the syntax would be, but essentially what you want to do is store the reference to the objClassCollection object, inside of each objClass instance.)
3. In objClass, instead of raising an event, directly call the StartMakingClass or FinishedMakingClass procedures of the objClassCollection object, which you've got a reference to inside each objClass object.
(VB6 syntax -- assuming the local variable holding the objClassCollection object is called mParent)
mParent.StartMakingClass Me
(or)
mParent.FinishedMakingClas
4. In the objClassCollection object define the two events, then raise them from within the StartMakingClass and FinishedMakingClass procedures:
(VB6 syntax)
Public Event StartMakingClass ()
Public Event FinishedMakingClass ()
Public Sub StartMakingClass(Obj As objClass)
RaiseEvent StartMakingClass
End Sub
Public Sub FinishedMakingClass(Obj As objClass)
RaiseEvent FinishedMakingClass
End Sub
Now your form would declare the objClassCollection object WithEvents so that it can respond to these "events" from the individual objClass objects, channeled through the objClassCollection object.
Not sure if you can use any of this, but hope it helps.