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

RaiseEvent not firing...

P: n/a
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, nothing happens. Below are
some code snippets that show what I am doing. Can someone straighten
me out... I feel like this must be something real simple...

'------------------------------------------------------------------------------
Public Class frmMain
'In my main form, I declare my form with events so I can handle them
later...
Private WithEvents frmErrLog As frmErrorLog

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'In my main form, I create a new instance of another form, then open
it.
frmLogin = New frmDomainLogin(Me)
frmLogin.ShowDialog(Me) 'Wait here
till the form closes...
End Sub

Private Sub frmErrLog_LogError(ByVal strMethod
As String, ByVal strMessage As String) Handles frmErrLog.LogError
'In my main form, I want to catch the events raised from the other
form... but this code never gets executed... why not?
Msgbox("Logging error:" &
vbnewline & strMethod & vbnewline & strMessage)
End Sub
End Class
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
Public Class frmDomainLogin
'So, here I declare my event, for use later...
Public Event LogError(someParameter as Object)

Private Sub frmDomainLogin_Load(ByVal sender
As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent LogError(Now & "
raising test event...")
End Sub

End Class
'------------------------------------------------------------------------------

Oct 12 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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, nothing happens. Below are
some code snippets that show what I am doing. Can someone straighten
me out... I feel like this must be something real simple...

'------------------------------------------------------------------------------
Public Class frmMain
'In my main form, I declare my form with events so I can handle them
later...
Private WithEvents frmLogin As frmDomainLogin

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'In my main form, I create a new instance of another form, then open
it.
frmLogin = New frmDomainLogin(Me)
frmLogin.ShowDialog(Me) 'Wait here
till the form closes...
End Sub

Private Sub frmErrLog_LogError(ByVal strMethod
As String, ByVal strMessage As String) Handles frmErrLog.LogError
'In my main form, I want to catch the events raised from the other
form... but this code never gets executed... why not?
Msgbox("Logging error:" &
vbnewline & strMethod & vbnewline & strMessage)
End Sub
End Class
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
Public Class frmDomainLogin
'So, here I declare my event, for use later...
Public Event LogError(someParameter as Object)

Private Sub frmDomainLogin_Load(ByVal sender
As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent LogError(Now & "
raising test event...")
End Sub

End Class
'------------------------------------------------------------------------------

Oct 12 '07 #2

P: n/a
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, nothing happens. Below are
some code snippets that show what I am doing. Can someone straighten
me out... I feel like this must be something real simple...

'------------------------------------------------------------------------------
Public Class frmMain
'In my main form, I declare my form with events so I can handle them
later...
Private WithEvents frmLogin As frmDomainLogin

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'In my main form, I create a new instance of another form, then open
it.
frmLogin = New frmDomainLogin(Me)
frmLogin.ShowDialog(Me) 'Wait here
till the form closes...
End Sub

Private Sub frmErrLog_LogError(ByVal strMethod
As String, ByVal strMessage As String) Handles frmErrLog.LogError
'In my main form, I want to catch the events raised from the other
form... but this code never gets executed... why not?
Msgbox("Logging error:" &
vbnewline & strMethod & vbnewline & strMessage)
End Sub
End Class
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
Public Class frmDomainLogin
'So, here I declare my event, for use later...
Public Event LogError(someParameter as Object)

Private Sub frmDomainLogin_Load(ByVal sender
As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent LogError(Now & "
raising test event...")
End Sub

End Class
'------------------------------------------------------------------------------

Oct 12 '07 #3

P: n/a
"hzgt9b" <ce******@gmail.comschrieb
Private WithEvents frmLogin As frmDomainLogin
frmLogin = New frmDomainLogin(Me)
Private Sub frmErrLog_LogError(ByVal
strMethod As String, ByVal strMessage As String) Handles
frmErrLog.LogError 'In my main form, I want to catch the events
raised from the other form... but this code never gets executed...
why not?
"Handles frmErrLog.LogError": Above you write frmLogin, not frmErrLog. Is
this accidently in this posting?
Armin
Oct 12 '07 #4

P: n/a
Armin,
Yes, that was a typo... consider frmLogin and frmErrLog the same form.

Oct 12 '07 #5

P: n/a
hzgt9b,

I tried re-creating your scenario in a simple example and I did not have any
problems raising an event in a form being shown modally and handling the
event in the parent form.

Perhaps something else in your application is complicating the situation.

Kerry Moorman
"hzgt9b" wrote:
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, nothing happens. Below are
some code snippets that show what I am doing. Can someone straighten
me out... I feel like this must be something real simple...

'------------------------------------------------------------------------------
Public Class frmMain
'In my main form, I declare my form with events so I can handle them
later...
Private WithEvents frmErrLog As frmErrorLog

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'In my main form, I create a new instance of another form, then open
it.
frmLogin = New frmDomainLogin(Me)
frmLogin.ShowDialog(Me) 'Wait here
till the form closes...
End Sub

Private Sub frmErrLog_LogError(ByVal strMethod
As String, ByVal strMessage As String) Handles frmErrLog.LogError
'In my main form, I want to catch the events raised from the other
form... but this code never gets executed... why not?
Msgbox("Logging error:" &
vbnewline & strMethod & vbnewline & strMessage)
End Sub
End Class
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
Public Class frmDomainLogin
'So, here I declare my event, for use later...
Public Event LogError(someParameter as Object)

Private Sub frmDomainLogin_Load(ByVal sender
As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent LogError(Now & "
raising test event...")
End Sub

End Class
'------------------------------------------------------------------------------

Oct 13 '07 #6

P: n/a
"hzgt9b" <ce******@gmail.comschrieb
Armin,
Yes, that was a typo... consider frmLogin and frmErrLog the same
form.
Then I don't see an error in the code.
Armin

Oct 14 '07 #7

P: n/a
"hzgt9b" <ce******@gmail.comwrote in message
news:11*********************@z24g2000prh.googlegro ups.com...
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, nothing happens. Below are
some code snippets that show what I am doing. Can someone straighten
me out... I feel like this must be something real simple...

'------------------------------------------------------------------------------
Public Class frmMain
'In my main form, I declare my form with events so I can handle them
later...
Private WithEvents frmErrLog As frmErrorLog

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'In my main form, I create a new instance of another form, then open
it.
frmLogin = New frmDomainLogin(Me)
frmLogin.ShowDialog(Me) 'Wait here
till the form closes...
End Sub

Private Sub frmErrLog_LogError(ByVal strMethod
As String, ByVal strMessage As String) Handles frmErrLog.LogError
'In my main form, I want to catch the events raised from the other
form... but this code never gets executed... why not?
Msgbox("Logging error:" &
vbnewline & strMethod & vbnewline & strMessage)
End Sub
End Class
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
Public Class frmDomainLogin
'So, here I declare my event, for use later...
Public Event LogError(someParameter as Object)

Private Sub frmDomainLogin_Load(ByVal sender
As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent LogError(Now & "
raising test event...")
End Sub

End Class
'------------------------------------------------------------------------------
I have had problems with the same thing. Code that worked for the last 12
months suddently stopped responding to a raised event. I suspect that given
certain very bizarre conditions, VB.Net is causing this. Sadly, I was never
able to find the answer. Other events continue to work fine.
I resolved the problem by using binding rather than raise an event of my
own...Not much of an answer, but days of trying different things, including
deleting and rewriting a class, proved futile.
Oct 14 '07 #8

P: n/a
"hzgt9b" <ce******@gmail.comwrote in message
news:11*********************@z24g2000prh.googlegro ups.com...
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, nothing happens. Below are
some code snippets that show what I am doing. Can someone straighten
me out... I feel like this must be something real simple...

'------------------------------------------------------------------------------
Public Class frmMain
'In my main form, I declare my form with events so I can handle them
later...
Private WithEvents frmErrLog As frmErrorLog

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'In my main form, I create a new instance of another form, then open
it.
frmLogin = New frmDomainLogin(Me)
frmLogin.ShowDialog(Me) 'Wait here
till the form closes...
End Sub

Private Sub frmErrLog_LogError(ByVal strMethod
As String, ByVal strMessage As String) Handles frmErrLog.LogError
'In my main form, I want to catch the events raised from the other
form... but this code never gets executed... why not?
Msgbox("Logging error:" &
vbnewline & strMethod & vbnewline & strMessage)
End Sub
End Class
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
Public Class frmDomainLogin
'So, here I declare my event, for use later...
Public Event LogError(someParameter as Object)

Private Sub frmDomainLogin_Load(ByVal sender
As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent LogError(Now & "
raising test event...")
End Sub

End Class
'------------------------------------------------------------------------------
Just to show you are not alone with this problem, try a Google on "VB.Net +
RaiseEvent not firing"
Oct 14 '07 #9

P: n/a

"Harry" <ha**********@ffapaysmart.com.auwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
"hzgt9b" <ce******@gmail.comwrote in message
news:11*********************@z24g2000prh.googlegro ups.com...
>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, nothing happens. Below are
some code snippets that show what I am doing. Can someone straighten
me out... I feel like this must be something real simple...

'------------------------------------------------------------------------------
Public Class frmMain
'In my main form, I declare my form with events so I can handle them
later...
Private WithEvents frmErrLog As frmErrorLog

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
'In my main form, I create a new instance of another form, then open
it.
frmLogin = New frmDomainLogin(Me)
frmLogin.ShowDialog(Me) 'Wait here
till the form closes...
End Sub

Private Sub frmErrLog_LogError(ByVal strMethod
As String, ByVal strMessage As String) Handles frmErrLog.LogError
'In my main form, I want to catch the events raised from the other
form... but this code never gets executed... why not?
Msgbox("Logging error:" &
vbnewline & strMethod & vbnewline & strMessage)
End Sub
End Class
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
Public Class frmDomainLogin
'So, here I declare my event, for use later...
Public Event LogError(someParameter as Object)

Private Sub frmDomainLogin_Load(ByVal sender
As Object, ByVal e As System.EventArgs) Handles Me.Load
RaiseEvent LogError(Now & "
raising test event...")
End Sub

End Class
'------------------------------------------------------------------------------
Just to show you are not alone with this problem, try a Google on "VB.Net
+ RaiseEvent not firing"
I did the google and noticed something that is similar to what you have.
Your event does not follow the ".net" signature with the first parameter
being the object which raised the event and the second parameter depending
on what is sent but is inherited from the EventArgs class.

Try changing your events to follow this pattern.

Can't hurt.

LS

Oct 14 '07 #10

P: n/a
THanks foe all the replies.

Oct 17 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.