Convert C# to VB.Adding Eventhandler.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Andersen

    #1

    Convert C# to VB.Adding Eventhandler.

    I have this piece of code I am trying to convert from c# to vb.net.
    It's a Windows project.

    This line gives me trouble ( I have tried to compress the code for
    readability. Hope I haven't screwed up):
    m_CA.AnEvent += new U.U_EventHandle r(evt);

    I assume this is a c# way of adding an additional eventhandler to an event?

    If I move this over to VB, I get an error at "AnEvent", and at "evt"
    The AnEvent error is "....Can't call directly. Use RaiseEvent...".
    The evt error is "....use addressof..."

    I don't know if the following information is useful.
    At the top of the code is
    private U.CC m_CA = null;

    and then there is a sub with
    m_CA = new U.CC();
    m_CA.AnEvent += new U.U_EventHandle r(evt);

    And then there is this sub
    private void evt(byte id, string data){......}

    somewhere inside U is
    public virtual event U_EventHandler AnEvent;

    tia
    /jim


  • Pritcham

    #2
    Re: Convert C# to VB.Adding Eventhandler.

    On 21 Feb, 12:47, "Jim Andersen" <nos...@nospam. dkwrote:
    I have this piece of code I am trying to convert from c# to vb.net.
    It's a Windows project.
    >
    This line gives me trouble ( I have tried to compress the code for
    readability. Hope I haven't screwed up):
    m_CA.AnEvent += new U.U_EventHandle r(evt);
    >
    I assume this is a c# way of adding an additional eventhandler to an event?
    >
    If I move this over to VB, I get an error at "AnEvent", and at "evt"
    The AnEvent error is "....Can't call directly. Use RaiseEvent...".
    The evt error is "....use addressof..."
    >
    I don't know if the following information is useful.
    At the top of the code is
    private U.CC m_CA = null;
    >
    and then there is a sub with
    m_CA = new U.CC();
    m_CA.AnEvent += new U.U_EventHandle r(evt);
    >
    And then there is this sub
    private void evt(byte id, string data){......}
    >
    somewhere inside U is
    public virtual event U_EventHandler AnEvent;
    >
    tia
    /jim
    Hi

    Something like "AddHandler m_CA.AnEvent, AddressOf evt" ?

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Convert C# to VB.Adding Eventhandler.

      "Jim Andersen" <nospam@nospam. dkschrieb:
      >I have this piece of code I am trying to convert from c# to vb.net.
      It's a Windows project.
      >
      This line gives me trouble ( I have tried to compress the code for
      readability. Hope I haven't screwed up):
      m_CA.AnEvent += new U.U_EventHandle r(evt);
      \\\
      AddHandler m_CA.AnEvent, AddressOf evt
      ///
      I assume this is a c# way of adding an additional eventhandler to an
      event?
      'AddHandler'/'RemoveHandler' are supported by VB and work pretty similar.
      In addition, VB supports 'WithEvent' declarations of type-level variables.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      Working...