Results 1 to 7 of 7

Thread: [RESOLVED] Need the VB .NET equivalent of this.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    Resolved [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.

  2. #2
    New Member GinGin's Avatar
    Join Date
    Oct 2010
    Posts
    13

    Re: Need the VB .NET equivalent of this.

    vb Code:
    1. AddHandler Mycls.MyEvent, AddressOf MyClass.MyEventHandler()

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2009
    Posts
    435

    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.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width