Public Shared Event doesn't work..?

jdezeeuw
08-19-2005, 12:31 PM
Hi there,

I'm trying to build a class (Class1) with a Public Shared Sub wich is raising an Public Shared Event wich I want to catch in another class (Form1).

I wonder why the event doesn't occur and the sub OnNewPerson isn't being executed.

Here's my form1:
Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub OnNewPerson()
MsgBox("new person")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Class1.subNewPerson()

AddHandler Class1.NewPerson, AddressOf OnNewPerson

End Sub
End Class

and here's the class:

Public Class Class1

Public Shared Event NewPerson()


Public Shared Sub subNewPerson()
RaiseEvent NewPerson()
End Sub

End Class

Can anybody advise me here? Thanks in advance!

Jeroen.

wayneph
08-19-2005, 12:49 PM
It looks like you're trying to fire the event before you're listening for it.

Try switching the order of these lines...

Class1.subNewPerson()

AddHandler Class1.NewPerson, AddressOf OnNewPerson

jdezeeuw
08-19-2005, 01:00 PM
Thanks. Didn't saw that.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum