473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Public Events

What is the advantage of declaring events in #2 over #1. Which one
should be used?

#1
Public Event MyEvent(sender as object, e as eventargs)

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

#2
Public Delegate Sub MyEventHandler(sender as object, e as eventargs)

Public Event MyEvent as MyEventHandler

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

Mar 6 '07 #1
3 1134
"Charlie Brown" <cb****@duclaw.comschrieb:
What is the advantage of declaring events in #2 over #1. Which one
should be used?

#1
Public Event MyEvent(sender as object, e as eventargs)

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

#2
Public Delegate Sub MyEventHandler(sender as object, e as eventargs)

Public Event MyEvent as MyEventHandler

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub
#2 allows you to reuse the delegate type for more than one event.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Mar 7 '07 #2
#2 is more like C# does it. Either way is pretty much the same. If you use
#1, VB creates an Delegate under the covers. I like #1... less coding on my
part :-)

======================================
David McCarter [Microsoft VB.NET MVP]
www.vsdntips.com
VSDN Tips & Tricks .NET Coding Standards available at:
www.cafepress.com/vsdntips.20412485
"Charlie Brown" wrote:
What is the advantage of declaring events in #2 over #1. Which one
should be used?

#1
Public Event MyEvent(sender as object, e as eventargs)

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

#2
Public Delegate Sub MyEventHandler(sender as object, e as eventargs)

Public Event MyEvent as MyEventHandler

Private Sub DoSomething()
RaiseEvent MyEvent(nothing, nothing)
End Sub

Mar 7 '07 #3
Good to know, thanks for the reply.

Mar 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: VK | last post by:
Folks, An aspx page has some querystring variables in the URL. In the code beind file, I tried requesting these variables and setting as public variables, so it is not specific to a sub. ...
4
by: Tamir Khason | last post by:
I have a control with custom events, fired by events occured from inside the control. But I can not see those events in design time from Properties window. What's wrong??? Following the code: ...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
5
by: Rene | last post by:
I created a class (SomeClass), on that class, I declared a delegate (OnXyz) and then declared an event based on that delegate (Xyz). All this in the same class. After that, I created another class...
6
by: Paperback Writer | last post by:
I have 30 textBox in my UserControl...they are with PROTECTED modifier. But i need to access these TextBox throught my WebForm... What is the best way to access them ? leaving PROTECTED and...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
1
by: jmhmaine | last post by:
I'm converting C# code to VB.Net and I completed everything but a couple lines. I'm receiving an error Calling Public Event directly. Here is the relevant code: Public Class ...
1
by: vbisjustforme | last post by:
Hello, I am working on a windows dll and this is my problem: 'api Public Declare Function myFunction Lib "Functionmine.dll" (byval ProgieName as String) as Boolean 'entry point in module...
7
by: Jeff | last post by:
I need a way to do the following and cannot seem to find a solution via google. 1. Have a method from the main app to get all open forms 2. Check each open form for a public method 3. If this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.