By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,496 Members | 1,517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,496 IT Pros & Developers. It's quick & easy.

RaiseEvent... vs Calling Sub directly?

P: n/a
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
---------------------------------------------------

Thanks,
Ron
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a

Jan. 6, 2005

By using events, more than one method or component can handle the
same event....

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

Sub SECONDTEST(byval msg as string) handles c1.testevent
Do some more work here........
end sub
End Class

So if more than one person had the instance of c1 then all of them (on
seperate computers such as .Net Remoting) could display the message on their
computers. It is sort of like a newsletter where multiple people sign up for
the same event (publishing a new edition). So in conclusion, if other
components are using your class that might want to also handle the event,
then you should use events. If this reply helped you, then please click on
the "Yes" box above this message! I hope this
helps to clear up some of the details!
Joseph MCAD
"Ron" wrote:
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
---------------------------------------------------

Thanks,
Ron

Nov 21 '05 #2

P: n/a
Ron
Hi Joseph,

Thanks for your explanation. Yes, it did clear things up
for me. But I don't see a "Yes" box above the message for
me to click on.

Question: Your explanation sounds similar to using
Delegates. May I ask if there is a similarity here? If
yes, what would be the subtle difference between using
Events or Delegates?

Thanks for your help,
Ron

-----Original Message-----

Jan. 6, 2005

By using events, more than one method or component can handle thesame event....

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

Sub SECONDTEST(byval msg as string) handles c1.testevent
Do some more work here........
end sub
End Class

So if more than one person had the instance of c1 then all of them (onseperate computers such as .Net Remoting) could display the message on theircomputers. It is sort of like a newsletter where multiple people sign up forthe same event (publishing a new edition). So in conclusion, if othercomponents are using your class that might want to also handle the event,then you should use events. If this reply helped you, then please click onthe "Yes" box above this message! I hope this
helps to clear up some of the details!

Joseph MCAD
"Ron" wrote:
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
---------------------------------------------------

Thanks,
Ron

.

Nov 21 '05 #3

P: n/a
The other issue is knowing which sub to call. Let's say you are a button and
you need to mimic raisin the click event so someone knows you were just
clicked. How would you do this? You don't know what object you are on - a
form, a usercontrol? You don't know what method the developer wants to get
called to be notified that the button was clicked.

It would be impossible to implement a button click event by just calling
known methods.

"Ron" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
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
---------------------------------------------------

Thanks,
Ron

Nov 21 '05 #4

P: n/a

Jan. 6, 2005

I don't understand what Marina means. The difference between events
and delegates is that with events you use AddHandler Obj.Event, AddressOf
Method while with delegates you can submit them across networks and the
internet. Then the component that you sent the delegate to can use
DelegateObj.Invoke which will invoke a method on the component that the
delegate came from. This acts like a callback. This way the component across
the internet can call a method on a different component when it is done
processing something without having to have the instance of the other
component. In other words... The delegate can be thought of your email
address that you give the newsletter component. The newsletter can (across
the network or internet) then use the email address to send you (callback)
the newsletter when it publishes a new one (completes processing). If you
used events then the component across the internet would have to have an
object instance (access to your computer) of the component to callback. I
hope this is still understandable! The "Yes" button should be just above the
top of the message right under the information that shows the subject, from,
and in contents. Please look again for it! Thanks and have a great day! (Feel
free to ask more!)
Joseph MCAD

"Ron" wrote:
Hi Joseph,

Thanks for your explanation. Yes, it did clear things up
for me. But I don't see a "Yes" box above the message for
me to click on.

Question: Your explanation sounds similar to using
Delegates. May I ask if there is a similarity here? If
yes, what would be the subtle difference between using
Events or Delegates?

Thanks for your help,
Ron

-----Original Message-----

Jan. 6, 2005

By using events, more than one method or

component can handle the
same event....

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

Sub SECONDTEST(byval msg as string) handles c1.testevent
Do some more work here........
end sub
End Class

So if more than one person had the instance of c1 then

all of them (on
seperate computers such as .Net Remoting) could display

the message on their
computers. It is sort of like a newsletter where multiple

people sign up for
the same event (publishing a new edition). So in

conclusion, if other
components are using your class that might want to also

handle the event,
then you should use events. If this reply helped you,

then please click on
the "Yes" box above this message! I hope this
helps to clear up some of the details!

Joseph MCAD
"Ron" wrote:
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
---------------------------------------------------

Thanks,
Ron

.

Nov 21 '05 #5

P: n/a
I was saying, that unless you using events/delegates, there is no way to
register callbacks. The example in the post showed calling a specific
method in a specific class as a way of saying 'an event occurred'. Well, if
you are developing a button, you can't do that. What method would you call
to notify the user the someone just clicked the button? You can't - you need
to give the client a way to register for a callback.

I was giving another important example of why you would want events, vs.
calling a sub directly.

"Joseph MCAD" <Jo********@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...

Jan. 6, 2005

I don't understand what Marina means. The difference between events
and delegates is that with events you use AddHandler Obj.Event, AddressOf
Method while with delegates you can submit them across networks and the
internet. Then the component that you sent the delegate to can use
DelegateObj.Invoke which will invoke a method on the component that the
delegate came from. This acts like a callback. This way the component across the internet can call a method on a different component when it is done
processing something without having to have the instance of the other
component. In other words... The delegate can be thought of your email
address that you give the newsletter component. The newsletter can (across
the network or internet) then use the email address to send you (callback)
the newsletter when it publishes a new one (completes processing). If you
used events then the component across the internet would have to have an
object instance (access to your computer) of the component to callback. I
hope this is still understandable! The "Yes" button should be just above the top of the message right under the information that shows the subject, from, and in contents. Please look again for it! Thanks and have a great day! (Feel free to ask more!)
Joseph MCAD

"Ron" wrote:
Hi Joseph,

Thanks for your explanation. Yes, it did clear things up
for me. But I don't see a "Yes" box above the message for
me to click on.

Question: Your explanation sounds similar to using
Delegates. May I ask if there is a similarity here? If
yes, what would be the subtle difference between using
Events or Delegates?

Thanks for your help,
Ron

-----Original Message-----

Jan. 6, 2005

By using events, more than one method or

component can handle the
same event....

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

Sub SECONDTEST(byval msg as string) handles c1.testevent
Do some more work here........
end sub
End Class

So if more than one person had the instance of c1 then

all of them (on
seperate computers such as .Net Remoting) could display

the message on their
computers. It is sort of like a newsletter where multiple

people sign up for
the same event (publishing a new edition). So in

conclusion, if other
components are using your class that might want to also

handle the event,
then you should use events. If this reply helped you,

then please click on
the "Yes" box above this message! I hope this
helps to clear up some of the details!

Joseph MCAD
"Ron" wrote:

> 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
> ---------------------------------------------------
>
> Thanks,
> Ron
>
.

Nov 21 '05 #6

P: n/a

Jan. 6, 2005

Yes, you are right if you are developing controls that respond to
user generated events. I was saying things in the context of implementing
events for your own code in the same application or in a different
applications that use it directly in code, but not exposing it to the UI.
There is a difference between using the component in code and on the UI. I
believe this is where we had a misunderstanding of the context of what each
other was talking in terms of. I hope that I now have correctly interpreted
what you mean. Thanks and have a great day!
Joseph MCAD

"Joseph MCAD" wrote:

Jan. 6, 2005

By using events, more than one method or component can handle the
same event....

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

Sub SECONDTEST(byval msg as string) handles c1.testevent
Do some more work here........
end sub
End Class

So if more than one person had the instance of c1 then all of them (on
seperate computers such as .Net Remoting) could display the message on their
computers. It is sort of like a newsletter where multiple people sign up for
the same event (publishing a new edition). So in conclusion, if other
components are using your class that might want to also handle the event,
then you should use events. If this reply helped you, then please click on
the "Yes" box above this message! I hope this
helps to clear up some of the details!
Joseph MCAD
"Ron" wrote:
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
---------------------------------------------------

Thanks,
Ron

Nov 21 '05 #7

P: n/a
I don't think I really understand you. In any case where the component is a
library component - meaning it could be used in any project, it would have
to follow this model. Regardless of whether or not it had anything to do
with the UI. Example: a Timer component. Has nothing to do with UI, can be
created entirely in code, but needs to let the consumer know that the time
has elapsed. Events pretty much become necessary when you write a reusable
object that has behaviors that you need to extend.

I am not sure why you are debating this, as my post was just giving another
example of why one would want to use events. I did not contradict anything
you had said in your post.

"Joseph MCAD" <Jo********@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...

Jan. 6, 2005

Yes, you are right if you are developing controls that respond to
user generated events. I was saying things in the context of implementing
events for your own code in the same application or in a different
applications that use it directly in code, but not exposing it to the UI.
There is a difference between using the component in code and on the UI. I
believe this is where we had a misunderstanding of the context of what each other was talking in terms of. I hope that I now have correctly interpreted what you mean. Thanks and have a great day!
Joseph MCAD

"Joseph MCAD" wrote:

Jan. 6, 2005

By using events, more than one method or component can handle the same event....

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

Sub SECONDTEST(byval msg as string) handles c1.testevent
Do some more work here........
end sub
End Class

So if more than one person had the instance of c1 then all of them (on seperate computers such as .Net Remoting) could display the message on their computers. It is sort of like a newsletter where multiple people sign up for the same event (publishing a new edition). So in conclusion, if other
components are using your class that might want to also handle the event, then you should use events. If this reply helped you, then please click on the "Yes" box above this message! I hope this
helps to clear up some of the details!
Joseph MCAD
"Ron" wrote:
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
---------------------------------------------------

Thanks,
Ron

Nov 21 '05 #8

P: n/a

Jan. 6, 2005

I just realized that if you double click a post then it will come up
in a whole new window. That means that the "Yes" button will be at the bottom
of the message. If you could click it on my first post I would greatly
appreciate it! Thanks and I hope that your question has been answered.

"Ron" wrote:
Hi Joseph,

Thanks for your explanation. Yes, it did clear things up
for me. But I don't see a "Yes" box above the message for
me to click on.

Question: Your explanation sounds similar to using
Delegates. May I ask if there is a similarity here? If
yes, what would be the subtle difference between using
Events or Delegates?

Thanks for your help,
Ron

-----Original Message-----

Jan. 6, 2005

By using events, more than one method or

component can handle the
same event....

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

Sub SECONDTEST(byval msg as string) handles c1.testevent
Do some more work here........
end sub
End Class

So if more than one person had the instance of c1 then

all of them (on
seperate computers such as .Net Remoting) could display

the message on their
computers. It is sort of like a newsletter where multiple

people sign up for
the same event (publishing a new edition). So in

conclusion, if other
components are using your class that might want to also

handle the event,
then you should use events. If this reply helped you,

then please click on
the "Yes" box above this message! I hope this
helps to clear up some of the details!

Joseph MCAD
"Ron" wrote:
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
---------------------------------------------------

Thanks,
Ron

.

Nov 21 '05 #9

P: n/a
Ron wrote:
Greetings,

I am trying to understand the rational for Raising Events
instead of just calling a sub.

In general, events are useful when you have asynchronous or otherwise
unpredictable operations. For example, you might have a class that
monitors something (file system, database, etc.) and raises an event
when certain conditions are met.

Events are especially useful when you are programming hardware devices.
You can implement a class that controls various functions of a device,
and raises events when the functions are complete. Often the device
will have to be polled, but if you encapsulate that in the class the
user of the class only sees the XXX_Complete event. It's much cleaner.

Nov 21 '05 #10

P: n/a
Ron
So it seems that for basic hands off applications that
just do stuff like retrieiving files from an external
source on a scheduled basis or sending out emails
(scheduled daily basis) I could get by just calling a sub
directly rather than raising events. This is mostly
what I do

Or if multiple users are simultaneously using an
application then I could see raising events when
something happens.
-----Original Message-----
Ron wrote:
Greetings,

I am trying to understand the rational for Raising Events instead of just calling a sub.

In general, events are useful when you have asynchronous

or otherwiseunpredictable operations. For example, you might have a class thatmonitors something (file system, database, etc.) and raises an eventwhen certain conditions are met.

Events are especially useful when you are programming hardware devices.You can implement a class that controls various functions of a device,and raises events when the functions are complete. Often the devicewill have to be polled, but if you encapsulate that in the class theuser of the class only sees the XXX_Complete event. It's much cleaner.
.

Nov 21 '05 #11

P: n/a
Ron
Thanks again for all your replies. But, with all due
respect, I don't see a "Yes" button anywhere on
this "Post a New Message" window/form. There are only 2
buttons, "Send" "Cancel". I am posting
through "Microsoft Newsgroups -
microsoft.public.dotnet.languages.vb".

Regards,
Ron

-----Original Message-----

Jan. 6, 2005

I just realized that if you double click a post then it will come upin a whole new window. That means that the "Yes" button will be at the bottomof the message. If you could click it on my first post I would greatlyappreciate it! Thanks and I hope that your question has been answered.
"Ron" wrote:
Hi Joseph,

Thanks for your explanation. Yes, it did clear things up for me. But I don't see a "Yes" box above the message for me to click on.

Question: Your explanation sounds similar to using
Delegates. May I ask if there is a similarity here? If yes, what would be the subtle difference between using
Events or Delegates?

Thanks for your help,
Ron

>-----Original Message-----
>
> Jan. 6, 2005
>
> By using events, more than one method or

component can handle the
>same event....
>
> 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
>
> Sub SECONDTEST(byval msg as string) handles c1.testevent > Do some more work here........
> end sub
>End Class
>
> So if more than one person had the instance of c1 then
all of them (on
>seperate computers such as .Net Remoting) could
display the message on their
>computers. It is sort of like a newsletter where
multiple people sign up for
>the same event (publishing a new edition). So in

conclusion, if other
>components are using your class that might want to
also handle the event,
>then you should use events. If this reply helped you,

then please click on
>the "Yes" box above this message! I hope this
>helps to clear up some of the details!
>

> Joseph MCAD
>
>
>"Ron" wrote:
>
>> 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
>> ---------------------------------------------------
>>
>> Thanks,
>> Ron
>>
>.
>

.

Nov 21 '05 #12

P: n/a
Keep in mind, Joseph, that not everyone accesses the newsgroups the
same way you do. For example, I use Google Groups and there is no
"Yes" button to press. Others may use a dedicated newsreader
application.

Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.