Conversion to vb.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

could someone please help me convert this c# code to vb.net

public event EventHandler TextChanged {
add {
Events.AddHandler(EventTextChanged, value);
}
remove {
Events.RemoveHandler(EventTextChanged, value);
}
}
 
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
dot.state.fl.us> said:
Where you got this code from?

That's not c# code

What makes you say that? It looks okay to me, assuming that Events and
EventTextChanged are appropriately defined.
 
Actually, it is C# code. I can get something very similar to compile in VS
2003.
However, I can't find anything on MSDN about this and I could only find a
couple of references in google to "explicit event declaration" in C#. We
regularly test our converters on over 200 sample programs from Microsoft and
other sources and have yet to encounter anyone using this event declaration
form.

Also, nothing in VS help. The keywords "add" and "remove" are not even
keywords in C#. Very strange. (but we will be updating our Instant VB C# to
VB converter to deal with this).

Regards,
David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter
 
David Anton said:
Actually, it is C# code. I can get something very similar to compile in VS
2003.
However, I can't find anything on MSDN about this and I could only find a
couple of references in google to "explicit event declaration" in C#. We
regularly test our converters on over 200 sample programs from Microsoft and
other sources and have yet to encounter anyone using this event declaration
form.

I use it and advocate it, personally. The default way of handling
events locks "this" in C# (at least with the current MS compiler) which
I believe to be a bad idea.

See http://www.yoda.arachsys.com/csharp/threads/lockchoice.shtml for my
reasons and a better event pattern.
Also, nothing in VS help. The keywords "add" and "remove" are not even
keywords in C#. Very strange. (but we will be updating our Instant VB C# to
VB converter to deal with this).

It's in section 17.7.1 and 17.7.2 of the C# language specification
(ECMA numbering).
 
They're called event accessors. There's a bit on them in MSDN, and a bit
more in Hejlsberg's C# book. I can't remember the syntax, but they'll be in
VB.NET 2005 as well.
 
Thanks for the references Jon.
I wonder why coverage on it is so hard to find in most references?
I'm familiar with the general concept from C++...

I'm especially puzzled about why "add" and "remove" aren't even keywords !
 
David Anton said:
Thanks for the references Jon.
I wonder why coverage on it is so hard to find in most references?
I'm familiar with the general concept from C++...

I'm especially puzzled about why "add" and "remove" aren't even keywords !

It' this whole contextual keywod thing I'd guess, sorta like how "yield"
won't be a keyword in Whidbey.
 
:-)

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Where you got this code from?
:-) It sure is c# code my friend. Try Asp.net controls by micrososft press
Nikhil Kothari Chapter 9
 
David Anton said:
Thanks for the references Jon.
I wonder why coverage on it is so hard to find in most references?
I'm familiar with the general concept from C++...

I suspect many C# programmers only use the "event variable" type
pattern, without really thinking about it, unfortunately :(
I'm especially puzzled about why "add" and "remove" aren't even keywords !

As Sean says, I think it's because they don't need to be.
 
Its called Event Property Construct. Someone rightly said its not there
vb.net but will be there in 2005
The way you use this in Vb.NET is

AddHandler Me.TextChanged, AddressOf EventTextChanged
RemoveHandler Me.TextChanged, AddressOf EventTextChanged

Thanx for yr replies. The code is from Nikhil Kothari's Best seller ASP.NET
controls book.
 
Hi Jon,

Long time, no see. :)

You are right, I have to be honest and say that this is the first time I see
such a declaration before.

You always learn something new :)

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
 
Back
Top