RaiseEvent not firing...

H

hzgt9b

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
'------------------------------------------------------------------------------
 
H

hzgt9b

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
'------------------------------------------------------------------------------
 
H

hzgt9b

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
'------------------------------------------------------------------------------
 
A

Armin Zingler

hzgt9b said:
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
 
G

Guest

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
 
H

Harry

hzgt9b said:
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.
 
H

Harry

hzgt9b said:
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"
 
L

Lloyd Sheen

Harry said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top