473,480 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why can't check event instance is nothing?

In C# I can check whether an event instance is nothing or not

public event SomeEvent SomeClickEvent;
if (SomeClickEvent != null)
{
}

But when I do this in VB it returns an error message

Public Event SomeClickEvent As SomeEvent

If Not SomeClickEvent Is Nothing Then

End If

Error Message: Public Event SomeClickEvent is an event, and cannot be called
directly. Use an RaiseEvent statement to raise an event.

Hope some one can give insights into this.
Jan 16 '08 #1
1 4171
On 2008-01-16, Patrick <Pa*****@discussions.microsoft.comwrote:
In C# I can check whether an event instance is nothing or not

public event SomeEvent SomeClickEvent;
if (SomeClickEvent != null)
{
}

But when I do this in VB it returns an error message

Public Event SomeClickEvent As SomeEvent

If Not SomeClickEvent Is Nothing Then

End If

Error Message: Public Event SomeClickEvent is an event, and cannot be called
directly. Use an RaiseEvent statement to raise an event.

Hope some one can give insights into this.
The reason you usually do that in C# is that, you want to raise the
event without getting null reference exception :) You don't have that
problem in VB.NET - since RaiseEvent will take care of it for you, so
it's safe to just raise the event without checking...

That said, why do you need to check this?

--
Tom Shelton
Jan 16 '08 #2

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

Similar topics

4
1589
by: Chris | last post by:
Hi, I followed the the aricle http://support.microsoft.com/default.aspx?scid=kb;en-us;321525 and was able to execute a dts package in vb.net. I replaced all the "Console.WriteLine" with "msgbox"....
3
1721
by: Guadala Harry | last post by:
In the following line of code, what is the point of including the 'new' keyword? List.Changed -= new ChangedEventHandler(ListChanged); I'm just a bit confused because I thought 'new' was used...
11
1489
by: John Salerno | last post by:
My general problem with events seems to be that there are so many parts to them, and I'm not sure where they all go or when you use which parts. For example, there's the delegate, the event name,...
8
1372
by: John | last post by:
Hi Could someone give me pointers on how to change this code (belwo) into a simple class? Thanks Regards Imports System
4
14768
by: Michael Passalacqua | last post by:
In VB.NET, how do you check to see if an instance of your application is already running? Michael Passalacqua Portland Community College CIS Faculty *** Sent via Developersdex...
27
1902
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the...
0
1532
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
4
12410
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
1711
by: Dom | last post by:
In the days of VB, it was possible to do the following: "Call Button1_Click()", although there was some argument about whether this was asking for trouble. Is it possible to do it in CSharp? ...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.