|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
RaiseEventI have the code below and somehow the message from RaiseEvent doesn't pop up at all. Can someone help me please? '------CODE '------/form1.vb/VB2005/Framework20--------- Imports System Public Class Form1 Public Event TimeExpired(ByVal Status As String) Public Sub RaiseTimeExpiredEvent() RaiseEvent TimeExpired("Your time has run out") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click RaiseTimeExpiredEvent() End Sub End Class '-------END----------------- Thank you very much. P Nguyen Onokiyo <onok***@gmail.com> wrote in news:#CusKzZCHHA.3660
@TK2MSFTNGP06.phx.gbl: > I have the code below and somehow the message from RaiseEvent doesn't You need something to catch the event.> pop up at all. Can someone help me please? Spam Catcher wrote:
> Onokiyo <onok***@gmail.com> wrote in news:#CusKzZCHHA.3660 Hello Spam Catcher,> @TK2MSFTNGP06.phx.gbl: > >> I have the code below and somehow the message from RaiseEvent doesn't >> pop up at all. Can someone help me please? > > You need something to catch the event. Isn't the RaiseEvent statement supposed to pop message on the screen using the string parameter when it's being called? According to your suggestion, if I'm not mistaken, are you saying that I need to create an specific event handler to pop up a message? I'm kinda new to VB.NET, please forgive my little understanding. Thank you very much P Nguyen Onokiyo <onok***@gmail.com> wrote in news:u2NfxIaCHHA.3380
@TK2MSFTNGP04.phx.gbl: Show quoteHide quote > Spam Catcher wrote: No - MessageBox pops a message.>> Onokiyo <onok***@gmail.com> wrote in news:#CusKzZCHHA.3660 >> @TK2MSFTNGP06.phx.gbl: >> >>> I have the code below and somehow the message from RaiseEvent doesn't >>> pop up at all. Can someone help me please? >> >> You need something to catch the event. > > Hello Spam Catcher, > > Isn't the RaiseEvent statement supposed to pop message on the screen > using the string parameter when it's being called? RaiseEvent fires the event. > According to your suggestion, if I'm not mistaken, are you saying that public Sub MyEventHandler(Byval Message as string) handles me.MyEventI > need to create an specific event handler to pop up a message? Msgbox(Message) End Sub BTW, you can register event handlers dynamically using the code: AddHandler Me.MyEvent, Addressof MyEventHandler Spam Catcher wrote:
Show quoteHide quote > Onokiyo <onok***@gmail.com> wrote in news:u2NfxIaCHHA.3380 Hi Spam Catcher,> @TK2MSFTNGP04.phx.gbl: > >> Spam Catcher wrote: >>> Onokiyo <onok***@gmail.com> wrote in news:#CusKzZCHHA.3660 >>> @TK2MSFTNGP06.phx.gbl: >>> >>>> I have the code below and somehow the message from RaiseEvent > doesn't >>>> pop up at all. Can someone help me please? >>> You need something to catch the event. >> Hello Spam Catcher, >> >> Isn't the RaiseEvent statement supposed to pop message on the screen >> using the string parameter when it's being called? > > No - MessageBox pops a message. > > RaiseEvent fires the event. > > >> According to your suggestion, if I'm not mistaken, are you saying that > I >> need to create an specific event handler to pop up a message? > > > public Sub MyEventHandler(Byval Message as string) handles me.MyEvent > Msgbox(Message) > End Sub > > > BTW, you can register event handlers dynamically using the code: > > AddHandler Me.MyEvent, Addressof MyEventHandler Thank you for your technical help. I have the thing working now. You've made my day although there is a thunderstorm outside right now. :) Have a good day and happy Thanks Giving! P Nguyen
Show quote
Hide quote
> '------CODE The event is being raised, but it is not being "handled" by anything. You > '------/form1.vb/VB2005/Framework20--------- > > Imports System > > Public Class Form1 > Public Event TimeExpired(ByVal Status As String) > > Public Sub RaiseTimeExpiredEvent() > RaiseEvent TimeExpired("Your time has run out") > End Sub > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > RaiseTimeExpiredEvent() > End Sub > End Class > need to add a handler for this event to be handled by the form that originates it, which of course would be quite superfluous because you can just as well handle the event in Button1_Click or RaiseTimeExpiredEvent. The main use of raiseevent is to signal to a parent or owner object that something has happened. For example, your button has raised a "Click" event which has been "Handled" by your form. Robinson wrote:
Show quoteHide quote >> '------CODE Hi Rob,>> '------/form1.vb/VB2005/Framework20--------- >> >> Imports System >> >> Public Class Form1 >> Public Event TimeExpired(ByVal Status As String) >> >> Public Sub RaiseTimeExpiredEvent() >> RaiseEvent TimeExpired("Your time has run out") >> End Sub >> >> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> System.EventArgs) Handles Button1.Click >> RaiseTimeExpiredEvent() >> End Sub >> End Class >> > > The event is being raised, but it is not being "handled" by anything. You > need to add a handler for this event to be handled by the form that > originates it, which of course would be quite superfluous because you can > just as well handle the event in Button1_Click or RaiseTimeExpiredEvent. > The main use of raiseevent is to signal to a parent or owner object that > something has happened. For example, your button has raised a "Click" event > which has been "Handled" by your form. > > Your explanation is awesome! Thank you very much, I have it working now. P Nguyen Onokiyo wrote:
> I have the code below and somehow the message from RaiseEvent doesn't I would strongly recommend you use the same Event model as Our Friends > pop up at all. Can someone help me please? > Public Sub RaiseTimeExpiredEvent() > RaiseEvent TimeExpired("Your time has run out") > End Sub in Redmond, specifically: Public Event XYZ( ByVal sender As Object, ByVal e As EventArgs ) That way, the code handling any event always has a reference to the object that sent it (in the sender argument) and you can create subclasses of EventArgs as necessary to wrap up all the information that you need to pass in the arguments (you can easily /add/ to these as time goes on). This is how I would put this together: Public Class Form1 ' The Event Public Event TimeExpired( _ ByVal sender as Object _ , ByVal e as TimeExpiredEventArgs _ ) ' The routine that raises the event; available to subclasses Protected Sub OnTimeExpired() Dim e As New TimeExpiredEventArgs RaiseEvent TimeExpired( e ) End Sub ' Another version of same, passing a custom event argument Protected Sub OnTimeExpired(ByVal e as TimeExpiredEventArgs) RaiseEvent TimeExpired( e ) End Sub ' The Argument class, containing everything we need to pass Public Class TimeExpiredEventArgs Inherits EventArgs ' Only THIS assembly can create these; nobody else ' Leave this out and you'll get a default, Public Constructor! Friend Sub New() MyBase.New() End Sub ' This is the message we're passing ... Public ReadOnly Property Message() as String Get Return m_sMessage End Get End Property ' ... and this is we it's stored internally Private m_sMessage as String = "Your time has run out" End Class End Class Then, elsewhere, you can handle this event using; Private Sub Thing_TimeExpired( _ ByVal sender As Object _ , ByVal e As TimeExpiredEventArgs _ ) Handles Thing.TimeExpired MsgBox( e.Message ) End Sub OK, this is probably *way* over the top for your application, but using sender and eventargs is definitely the way to go... HTH, Phill W.
Howto Identify an Exception?
vb 2005 standard question Can a base class implement a method on an interface for me? how mutch memory aspnet_wp.exe must use Class.New and DB mapping Thread synchronization. SECURITY PROBLEMS IN VB.NET Using Visual Studio .NET 2005 to compile to ASP.NET 1.1 VS2005 SP1 beta one more thing |
|||||||||||||||||||||||