-1

Here is the Interface

Public Interface ILoginConductor
    Inherits IHandle(Of LoginEvent)
    Inherits IHandle(Of LogoutEvent)
    Inherits IHandle(Of ExitEvent)
End Interface

In C# here is the method that uses the interface

public void Handle(LoginEvent message)
{
    LoginWindow loginWindow = new LoginWindow();
    loginWindow.Login += new EventHandler<LoginEventArgs>(this.LoginWindow_Login);
    loginWindow.Cancel += new EventHandler(LoginWindow_Cancel);
    loginWindow.ShowDialog();
}

And it converts to this in VB.Net

Public Sub Handle(message As LoginEvent) Implements    ILoginConductor.Handle
    Dim loginWindow As New LoginWindow()
    loginWindow.Login += New EventHandler(Of LoginEventArgs)(AddressOf Me.LoginWindow_Login)
    loginWindow.Cancel += New EventHandler(AddressOf LoginWindow_Cancel)
    loginWindow.ShowDialog()
End Sub

But the compiler throws a error which says that I must use a RaiseEvent. Could someone please help me to show me how to fix my code.

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • What do you mean "converts to"? Are you using a conversion tool? If so, which one? The issue is because VB doesn't have the += operator. You instead need to use the [RaiseEvent statement](https://msdn.microsoft.com/en-us/library/fwd3bwed.aspx). – Clint Nov 26 '16 at 16:33
  • 2
    @Clint : The VB.NET equivalent of `+=` is infact the [**AddHandler statement**](https://msdn.microsoft.com/en-us/library/7taxzxka.aspx), not RaiseEvent. – Visual Vincent Nov 26 '16 at 16:37
  • @VisualVincent that it does! Silly oversight on my part. – Clint Nov 26 '16 at 22:58

1 Answers1

0

Probably the compiler tells you that the events in the VB code must be triggered in a different way than C# does. You need to perpend the "raiseevent" keyword before the event method call (eg raiseevent Login_WindowCancel()). Take a look here https://msdn.microsoft.com/en-us/library/fwd3bwed.aspx

  • 1
    The compiler interprets it incorrectly. The actual equivalent of `+=` in this case is the [**AddHandler statement**](https://msdn.microsoft.com/en-us/library/7taxzxka.aspx). – Visual Vincent Nov 26 '16 at 16:39
  • Also see [**How to: Subscribe to and Unsubscribe from Events (C# Programming Guide)**](https://msdn.microsoft.com/en-us/library/ms366768.aspx). – Visual Vincent Nov 26 '16 at 16:42
  • Thanks for your help but I am still troubled. – user3418258 Nov 27 '16 at 16:36
  • Thanks for your help but I am still troubled. – user3418258 Nov 27 '16 at 16:37
  • While I am familiar with the use of RaiseEvent the link above to subscribing unfortunately does not have a VB equivalent. A simple example of addhandler to the original code sample would do the trick. – user3418258 Nov 27 '16 at 16:45
  • I finally found the correct syntax – user3418258 Nov 28 '16 at 16:14
  • RaiseEvent(AddHandler New EventHandler(Of LoginEventArgs)(AddressOf Me.LoginWindow_Login) RaiseEvent(AddHandler New EventHandler(AddressOf LoginWindow_Cancel) – user3418258 Nov 28 '16 at 16:15
  • Problem still is not solved. I Still have the wrong syntax in my example above, so need a VB expert here to show me what to do. – user3418258 Nov 28 '16 at 18:15