R
Ron
Greetings,
I am trying to understand the rational for Raising Events
instead of just calling a sub. Could someone explain the
difference between the following 2 scenarios? Why would I
want to raise an event instead of just calling the sub?
Scenario1 -- Using Events
------------------------------------------------------
Public Class Form1
Private WithEvents c1 As clsTest
Sub Testing()
c1 = New clsTest()
c1.TestSub()
End Sub
Sub cTest(ByVal Msg As String) Handles c1.TestEvent
MsgBox Msg
End Sub
End Class
-----------------------------------------------------
Public Class clsTest
Public Event TestEvent(ByVal Msg As String)
Public Sub TestSub
Dim strTemp As String = "testing"
RaiseEvent TestEvent(strTemp)
End Sub
End Class
*****************************************************
*****************************************************
Scenario2 -- No Events
-----------------------------------------------------
Public Class Form1
Dim c1 As clsTest
Sub Testing()
c1 = New clsTest()
c1.TestSub
End Sub
End Class
-----------------------------------------------------
Public Class clsTest
Public Sub TestSub
Test2Sub()
End Sub
Private Sub Test2Sub()
MsgBox "Testing"
End Sub
End Class
I am trying to understand the rational for Raising Events
instead of just calling a sub. Could someone explain the
difference between the following 2 scenarios? Why would I
want to raise an event instead of just calling the sub?
Scenario1 -- Using Events
------------------------------------------------------
Public Class Form1
Private WithEvents c1 As clsTest
Sub Testing()
c1 = New clsTest()
c1.TestSub()
End Sub
Sub cTest(ByVal Msg As String) Handles c1.TestEvent
MsgBox Msg
End Sub
End Class
-----------------------------------------------------
Public Class clsTest
Public Event TestEvent(ByVal Msg As String)
Public Sub TestSub
Dim strTemp As String = "testing"
RaiseEvent TestEvent(strTemp)
End Sub
End Class
*****************************************************
*****************************************************
Scenario2 -- No Events
-----------------------------------------------------
Public Class Form1
Dim c1 As clsTest
Sub Testing()
c1 = New clsTest()
c1.TestSub
End Sub
End Class
-----------------------------------------------------
Public Class clsTest
Public Sub TestSub
Test2Sub()
End Sub
Private Sub Test2Sub()
MsgBox "Testing"
End Sub
End Class