Conversion to VB results in errors
-
Dear all :-) I converted a sample from C# to VB and get an error message. It looks simple, but still I don't understand... Would it be possible that C# allows calling an event directly, while VB doesn't? Or did my conversion tool go wrong? :doh: Here's the short sample code:
private void OnWaveControlContextMenuPopup(ContextMenu menu)
{
if (this.WControlContextMenuPopup == null)
return;
this.WControlContextMenuPopup(menu);
}where WControlContextMenuPopup is defined as an event:
public event WControlContextMenuPopupDelegate WaveControlContextMenuPopup;
After conversion I get the error message "Public Event WControlContextMenuPopup in an event and cannot be called directly. Use 'RaiseEvent'...". The error is shown in lines 2 and 5 of the converted code:
Private Sub OnWControlContextMenuPopup(menu As ContextMenu) If Me.WControlContextMenuPopup Is Nothing Then <----- Return End If Me.WControlContextMenuPopup(menu) <----- End Sub
What would I have to change in the VB code to get the required result without error? Thanks for some insight... :cool: Mick
-
Dear all :-) I converted a sample from C# to VB and get an error message. It looks simple, but still I don't understand... Would it be possible that C# allows calling an event directly, while VB doesn't? Or did my conversion tool go wrong? :doh: Here's the short sample code:
private void OnWaveControlContextMenuPopup(ContextMenu menu)
{
if (this.WControlContextMenuPopup == null)
return;
this.WControlContextMenuPopup(menu);
}where WControlContextMenuPopup is defined as an event:
public event WControlContextMenuPopupDelegate WaveControlContextMenuPopup;
After conversion I get the error message "Public Event WControlContextMenuPopup in an event and cannot be called directly. Use 'RaiseEvent'...". The error is shown in lines 2 and 5 of the converted code:
Private Sub OnWControlContextMenuPopup(menu As ContextMenu) If Me.WControlContextMenuPopup Is Nothing Then <----- Return End If Me.WControlContextMenuPopup(menu) <----- End Sub
What would I have to change in the VB code to get the required result without error? Thanks for some insight... :cool: Mick
Try something like this:
Private Sub OnWControlContextMenuPopup(menu As ContextMenu)
RaiseEvent WControlContextMenuPopup(menu)
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Dear all :-) I converted a sample from C# to VB and get an error message. It looks simple, but still I don't understand... Would it be possible that C# allows calling an event directly, while VB doesn't? Or did my conversion tool go wrong? :doh: Here's the short sample code:
private void OnWaveControlContextMenuPopup(ContextMenu menu)
{
if (this.WControlContextMenuPopup == null)
return;
this.WControlContextMenuPopup(menu);
}where WControlContextMenuPopup is defined as an event:
public event WControlContextMenuPopupDelegate WaveControlContextMenuPopup;
After conversion I get the error message "Public Event WControlContextMenuPopup in an event and cannot be called directly. Use 'RaiseEvent'...". The error is shown in lines 2 and 5 of the converted code:
Private Sub OnWControlContextMenuPopup(menu As ContextMenu) If Me.WControlContextMenuPopup Is Nothing Then <----- Return End If Me.WControlContextMenuPopup(menu) <----- End Sub
What would I have to change in the VB code to get the required result without error? Thanks for some insight... :cool: Mick
C# and VB have differing syntax for doing the same thing. C# uses a syntax that is identical to calling an actual method. The error mesage tells you exactly what to do.
RaiseEvent WControlContextMenuPopup(menu)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
C# and VB have differing syntax for doing the same thing. C# uses a syntax that is identical to calling an actual method. The error mesage tells you exactly what to do.
RaiseEvent WControlContextMenuPopup(menu)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Try something like this:
Private Sub OnWControlContextMenuPopup(menu As ContextMenu)
RaiseEvent WControlContextMenuPopup(menu)
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Thank you for your answer. Will I just ignore the whole "If..." part then? Because "If RaiseEvent..." doesn't work either. What is it actually supposed to do? Check for the result of an event???
Yes, you ignore the
if
code. All it does is check to see if a subscriber is attached before trying to raise the event. If VB.NET, withRaiseEvent
, you don't have to do that.A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Yes, that's correct;
RaiseEvent
handles that check for you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Yes, you ignore the
if
code. All it does is check to see if a subscriber is attached before trying to raise the event. If VB.NET, withRaiseEvent
, you don't have to do that.A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Yes, that's correct;
RaiseEvent
handles that check for you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer