Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Public Shared Event doesn't work..?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-19-2005, 11:31 AM
jdezeeuw's Avatar
jdezeeuw jdezeeuw is offline
Freshman
 
Join Date: Mar 2004
Location: the Netherlands
Posts: 48
Default Public Shared Event doesn't work..?


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:
Code:
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:

Code:
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.

Last edited by jdezeeuw; 08-19-2005 at 11:53 AM. Reason: please use [vb][/vb] tags for posting code
Reply With Quote
  #2  
Old 08-19-2005, 11:49 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

It looks like you're trying to fire the event before you're listening for it.

Try switching the order of these lines...

Code:
Class1.subNewPerson() AddHandler Class1.NewPerson, AddressOf OnNewPerson
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 08-19-2005, 12:00 PM
jdezeeuw's Avatar
jdezeeuw jdezeeuw is offline
Freshman
 
Join Date: Mar 2004
Location: the Netherlands
Posts: 48
Default

Thanks. Didn't saw that.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->