473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

RaiseEvent

Hello,

I 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
Nov 16 '06 #1
7 6506
Onokiyo <on*****@gmail.comwrote 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.
Nov 16 '06 #2
'------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
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.
Nov 16 '06 #3
Spam Catcher wrote:
Onokiyo <on*****@gmail.comwrote 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?

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
Nov 16 '06 #4
Onokiyo <on*****@gmail.comwrote in news:u2NfxIaCHHA.3380
@TK2MSFTNGP04.phx.gbl:
Spam Catcher wrote:
>Onokiyo <on*****@gmail.comwrote 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
Nov 16 '06 #5
Robinson wrote:
>'------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

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.

Hi Rob,

Your explanation is awesome! Thank you very much, I have it working now.

P Nguyen
Nov 16 '06 #6
Spam Catcher wrote:
Onokiyo <on*****@gmail.comwrote in news:u2NfxIaCHHA.3380
@TK2MSFTNGP04.phx.gbl:
>Spam Catcher wrote:
>>Onokiyo <on*****@gmail.comwrote 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
Hi Spam Catcher,

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
Nov 16 '06 #7
Onokiyo wrote:
I have the code below and somehow the message from RaiseEvent doesn't
pop up at all. Can someone help me please?
Public Sub RaiseTimeExpiredEvent()
RaiseEvent TimeExpired("Your time has run out")
End Sub
I would strongly recommend you use the same Event model as Our Friends
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.
Nov 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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 asynchronous socket. When connect callback is called, i...
8
by: Nicolas | last post by:
How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot. ******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher(); public delegate void...
2
by: Carl tam | last post by:
Hi everyone, I got a quite interesting problem myself and got stuck. I have an aspx page with a windows user control with it. in the Windows Control. I have a RaiseEvent statement, say...
20
by: Bob Day | last post by:
Using VS 2003, VB, MSDE... There are two threads, A & B, that continously run and are started by Sub Main. They instantiationsl of identical code. Thread A handles call activity on telephone...
2
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 Windos XP Professional PC, the program will not...
2
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 textbox. All I want to do is appendtext to a...
3
by: Martin | last post by:
Hi all, I'm having a problem when trying to raise an event in my custom control when a toolstripbutton enable state changes. The problem is that although the code to raise the event executes, my...
1
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 event to tell the main thread that it's done. I...
10
by: hzgt9b | last post by:
Using VS2005, VB.NET, I am developing a windows app. The application opens a couple of forms. While the forms are open I want to raise some events, such as logging errors - but I call RaiseEvent,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.