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.