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 12 6894
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
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 .
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
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 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 .
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 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 > .
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
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
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 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 .
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.
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. .
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 >> >. > .
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Guille |
last post by:
Hi all!
I'm having some weird behaviour in a .NET application i'm developing.
I'll try to explain:
I've created a Class that wraps an...
|
by: shachar |
last post by:
hi all.
in vb.net i can write RaiseEvent.
can i do it in C# also?
how?
thanks - shachar.
|
by: Lim |
last post by:
I've developed a program that raise an event. This program works fine on a Windows 2000 Professional PC. However when I try to run the program on a...
|
by: Adam |
last post by:
I cannot figure out what I'm doing wrong, can someone shed some light on
this for me?
I have the following code inside a working user control...
|
by: dmoonme |
last post by:
I'm trying to rename some files in a directory. Pretty basic stuff -
renaming the files works fine but the problem I have is updated the text in...
|
by: Terry Olsen |
last post by:
I have a program with a couple of long running processes that i'm calling on
a separate thread.
When the process is completed, I want to raise an...
|
by: ffa |
last post by:
I have a number of classes that declare a public Event called RefreshData:
Public Class Client
Implements INotifyPropertyChanged
Implements...
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
I have a C# logging assembly with a static constructor and methods that is
called from another C# Assembly that is used as a COM interface for a VB6...
|
by: anandamd |
last post by:
Hi,
I am a newbie to vb.net, I have converted C# code to vb.net using the online converter tools. I have got rid of all the error messages but there...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |