WithEvents -- how to trigger when nested deep in other classes?

R

Rob R. Ainscough

During the course of separating my Business code from UI code, I'm trying to
have nested class instances be able to RaiseEvent on my Form1 code. I'm not
have much success, it works with the immediate class, but if that class
calls another class that needs to trigger the same event, that event never
gets triggered. Can this be done?

----------------------------------------------------------------
Form1

Private WithEvents mClass1 As New myClass

Private Sub OnProgressStep(ByVal aStep As Integer) Handles
mClass1.ProgressStep
Form1.ProgressBar.Step = aStep
End Sub

IF mClass.SomeMethod Then
msgBox "Success"
End IF

----------------------------------------------------------------
myClass

Public Event ProgressStep()

Public Function SomeMethod() As Boolean

Dim anotherClass as New myOtherClass
anotherClass.OtherMethod()

End Function

-----------------------------------------------------------------
myOtherClass

Public Event ProgressStep()

Public Sub OtherMethod()

RaiseEvent ProgressStep

End Sub

I was hoping RaiseEvent ProgressStep in OtherMethod would trigger the event,
but it doesn't -- how do I make nested object instances trigger the same UI
event as the calling object instance?

thanks, Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top