0

I'm having problems translating this into VB:

public delegate void ChangeMessageEvent(string message);
public static event ChangeMessageEvent ChangeMessage = null;

Also this doesn't seem to work

if (oStatusManager.ChangeMessage != null)
        {
          oStatusManager.ChangeMessage(message);
          Application.DoEvents();

}

Error MSG:

'Public Shared Shadows Event ChangeMessage(message As String)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

VB Code:

I used developer fusion to convert it

Here nothing is underlined and says: End of statement expected

Public Delegate Sub ChangeMessageEvent(message As String)
Public Shared Event ChangeMessage As ChangeMessageEvent = Nothing

If oStatusManager.ChangeMessage IsNot Nothing Then
    oStatusManager.ChangeMessage(message)
    Application.DoEvents()
End If

for the above line

'Public Shared Event ChangeMessage(message As String)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

8
  • 1
    Exactly as the error message states. It's an event not a method. Commented Mar 25, 2014 at 20:42
  • This works perfectly in C# how can I get it to work in VB? Commented Mar 25, 2014 at 20:44
  • Show us your VB code. Might be able to tell you what's wrong with it. Commented Mar 25, 2014 at 20:44
  • 2
    msdn.microsoft.com/en-us/library/ms172877.aspx Commented Mar 25, 2014 at 20:47
  • 6
    Every time someone uses Application.DoEvents, I cry a little, die a little. Commented Mar 25, 2014 at 20:50

1 Answer 1

1

Two things - drop the " = Nothing" and use the hidden VB 'Event' field - or drop the conditional altogether since VB does the check within the 'RaiseEvent':

Public Delegate Sub ChangeMessageEvent(ByVal message As String)
Public Shared Event ChangeMessage As ChangeMessageEvent

Private Sub test()
    If oStatusManager.ChangeMessageEvent IsNot Nothing Then
        RaiseEvent oStatusManager.ChangeMessage(message)
        Application.DoEvents()
    End If
End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your reply mate, I still get "delegate Class 'ChangeMessageEvent' conflicts with a member implicitly declared for event 'ChangeMessage' in class 'oStatusManager'.
Remove the conditional altogether then - i.e., you don't need the "If oStatusManager..." condition at all.
I tried that, still get the same error on the definition: Public Shared Event ChangeMessage As ChangeMessageEvent
Change the name of the "ChangeMessage" event or change the name of the "ChangeMessageEvent" delegate - the VB hidden field "ChangeMessageEvent" is conflicting with the delegate's name.
The problem is that VB uses a hidden field named the same as the event with "Event" added to it, so if you name anything <event>Event, you'll get a conflict. The VB error messages aren't very good at making this clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.