|
-
Oct 17th, 2010, 07:15 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Need the VB .NET equivalent of this.
Code:
Dim Mycls as New MyClass
Mycls.MyEvent += new MyClass.MyEventHandler(Mycls_MyEvent);
Can someone convert this to VB .NET? I tried this, but it didn't work.
-
Oct 17th, 2010, 07:19 PM
#2
New Member
Re: Need the VB .NET equivalent of this.
vb Code:
AddHandler Mycls.MyEvent, AddressOf MyClass.MyEventHandler()
-
Oct 17th, 2010, 07:22 PM
#3
Re: Need the VB .NET equivalent of this.
Technically it would be:
Code:
AddHandler Mycls.MyEvent, New MyClass.MyEventHandler(AddressOf Mycls_MyEvent)
but that can be simplified to:
Code:
AddHandler Mycls.MyEvent, AddressOf Mycls_MyEvent
just as the C# code can be simplified to:
Code:
Mycls.MyEvent += Mycls_MyEvent;
-
Oct 17th, 2010, 07:41 PM
#4
Thread Starter
Hyperactive Member
Re: Need the VB .NET equivalent of this.
Code:
AddHandler Mycls.MyEvent, AddressOf Mycls_MyEvent(sender, e)
Error 1 Expression does not produce a value.
-
Oct 17th, 2010, 07:45 PM
#5
Re: Need the VB .NET equivalent of this.
Um, look at what you just posted and look at what I posted. Are they the same?
-
Oct 17th, 2010, 07:47 PM
#6
Thread Starter
Hyperactive Member
Re: Need the VB .NET equivalent of this.
Code:
AddHandler Mycls.MyEvent...
Warning 1 Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
-
Oct 17th, 2010, 08:00 PM
#7
Re: Need the VB .NET equivalent of this.
Didn't we discuss this in your other thread? How do you access a Shared member? Via the type itself, not an instance of the type. Do you do this?
Code:
Dim mb As New MessageBox
mb.Show("Hello World")
No, you don't. You do this:
Code:
MessageBox.Show("Hello World")
This is exactly the same. MyClass is a type and MyEvent is a Shared member of that type, so you access MyEvent via MyClass, not an instance of MyClass.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|