locked
Port SolutionEvents from C# to VB.Net RRS feed

  • Question

  • User1152836825 posted

     I am trying to use the SolutionEvents interface in Visual Studio and the sample it have is in C#. When I try to port it I get compile or run-time errors ("COM target does not implement IDispatch"). The problem is with the bold line on the bottom with the "+=" which does not work in VB. Removing the + causes a run-time error.

    The C# code is

    private static SolutionEvents _se = null;

    private static _dispSolutionEvents_OpenedEventHandler _openedEvent = null;

    private static _dispSolutionEvents_AfterClosingEventHandler _afterClosingEvent = null;

    private static _dispSolutionEvents_ProjectRemovedEventHandler _projectRemovedEvent = null;

    if (_se == null)

    {

        _se = _applicationObject.Events.SolutionEvents;

    }

    if (_openedEvent == null)

    {

        _openedEvent = new _dispSolutionEvents_OpenedEventHandler(se_Opened);

        _se.Opened += _openedEvent;

    }

     

    Saturday, July 3, 2010 10:36 PM

Answers

  • User1006193418 posted

    The problem is with the bold line on the bottom with the "+=" which does not work in VB.

    Removing the + causes a run-time error.

    Hi,

    VB.NET uses AddHandler and AddressOf key words to add a function to an event. You can have a try on this code.

    AddHandler _se.Opened, AddressOf _openedEvent

    For more information about this statement, please refer to MSND at http://msdn.microsoft.com/en-us/library/7taxzxka.aspx.

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 5, 2010 11:49 AM
  • User-952121411 posted

    As eluded to, the += operator in C# is how you can wire up events in code.  In VB.NET the AddHandler keyword reference is used to do the same operation. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 6, 2010 3:49 PM

All replies

  • User377791177 posted

    google


    Sunday, July 4, 2010 7:41 AM
  • User397347636 posted

    Use 'AddHandler'. 

    Sunday, July 4, 2010 7:22 PM
  • User1006193418 posted

    The problem is with the bold line on the bottom with the "+=" which does not work in VB.

    Removing the + causes a run-time error.

    Hi,

    VB.NET uses AddHandler and AddressOf key words to add a function to an event. You can have a try on this code.

    AddHandler _se.Opened, AddressOf _openedEvent

    For more information about this statement, please refer to MSND at http://msdn.microsoft.com/en-us/library/7taxzxka.aspx.

    Best Regards,
    Shengqing Yang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 5, 2010 11:49 AM
  • User-952121411 posted

    As eluded to, the += operator in C# is how you can wire up events in code.  In VB.NET the AddHandler keyword reference is used to do the same operation. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 6, 2010 3:49 PM