Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

RaiseEvent not firing...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hzgt9b - 12 Oct 2007 17:00 GMT
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
'------------------------------------------------------------------------------
hzgt9b - 12 Oct 2007 17:02 GMT
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
'------------------------------------------------------------------------------
hzgt9b - 12 Oct 2007 17:02 GMT
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
'------------------------------------------------------------------------------
Armin Zingler - 12 Oct 2007 18:34 GMT
>                        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
hzgt9b - 12 Oct 2007 19:44 GMT
Armin,
Yes, that was a typo... consider frmLogin and frmErrLog the same form.
Armin Zingler - 14 Oct 2007 12:26 GMT
> Armin,
> Yes, that was a typo... consider frmLogin and frmErrLog the same
> form.

Then I don't see an error in the code.

Armin
Kerry Moorman - 13 Oct 2007 16:40 GMT
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

> Using VS2005, VB.NET,
> I am developing a windows app. The application opens a couple of
[quoted text clipped - 41 lines]
>             End Class
> '------------------------------------------------------------------------------
Harry - 14 Oct 2007 21:47 GMT
> Using VS2005, VB.NET,
> I am developing a windows app. The application opens a couple of
[quoted text clipped - 41 lines]
>            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.
Harry - 14 Oct 2007 21:52 GMT
> Using VS2005, VB.NET,
> I am developing a windows app. The application opens a couple of
[quoted text clipped - 41 lines]
>            End Class
> '------------------------------------------------------------------------------

Just to show you are not alone with this problem, try a Google on "VB.Net +
RaiseEvent not firing"
Lloyd Sheen - 14 Oct 2007 22:07 GMT
>> Using VS2005, VB.NET,
>> I am developing a windows app. The application opens a couple of
[quoted text clipped - 44 lines]
> 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
hzgt9b - 17 Oct 2007 03:20 GMT
THanks foe all the replies.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.