Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

BeginInvoke event call to VB.NET


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Headkaze   Members   -  Reputation: 485

Like
0Likes
Like

Posted 10 March 2012 - 12:18 AM

I'm trying to convert some C# event handling code to VB.NET using the online converters but they are not converting it correctly and I tried a few different ones.

public event PacAttachedDelegate OnPacAttached = null;
public event PacRemovedDelegate OnPacRemoved = null;

void PacAttachedCallback(int id)
{
	m_numDevices++;

	if (OnPacAttached != null)
		m_ctrl.BeginInvoke(OnPacAttached, id);
}

void PacRemovedCallback(int id)
{
	m_numDevices--;

	if (OnPacRemoved != null)
		m_ctrl.BeginInvoke(OnPacRemoved, id);
}

Converts to

Public Event OnPacAttached As PacAttachedDelegate = Nothing
Public Event OnPacRemoved As PacRemovedDelegate = Nothing

Private Sub PacAttachedCallback(id As Integer)
	m_numDevices += 1

	If OnPacAttached IsNot Nothing Then
		m_ctrl.BeginInvoke(OnPacAttached, id)
	End If
End Sub

Private Sub PacRemovedCallback(id As Integer)
	m_numDevices -= 1

	If OnPacRemoved IsNot Nothing Then
		m_ctrl.BeginInvoke(OnPacRemoved, id)
	End If
End Sub

Here are the errors I'm getting. I have searched over the web and tried different things but nothing works (for example I tried m_ctrl.BeginInvoke(New PacAttachedDelegate(AddressOf OnPacAttached), id))

Error 1 End of statement expected.
Error 2 End of statement expected.
Error 3 'Public Event OnPacAttached(id As Integer)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Error 4 'Public Event OnPacAttached(id As Integer)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Error 5 'Public Event OnPacRemoved(id As Integer)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

Ad:

#2 Headkaze   Members   -  Reputation: 485

Like
-1Likes
Like

Posted 10 March 2012 - 05:26 PM

VB.NET sucks doesn't it?

Unfortunately I have to have example code in several languages.

Any help would be greatly appreciated.

#3 assainator   Members   -  Reputation: 198

Like
0Likes
Like

Posted 11 March 2012 - 05:44 PM

Could you tell us to what line the errors point?

VB.NET sucks doesn't it?

Why is that exactly?

Also, why don't you keep it in C#, then import it as an assembly in vb.net?
"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me


#4 Headkaze   Members   -  Reputation: 485

Like
0Likes
Like

Posted 11 March 2012 - 08:01 PM

Could you tell us to what line the errors point?


Error 1 and 2 are caused by the "= Nothing". The other errors are on the BeginInvoke lines.

Why is that exactly?


Just my opinion. Not a big fan of the syntax.

Also, why don't you keep it in C#, then import it as an assembly in vb.net?


No can do unfortunately. These are small examples for an SDK that p/invoke a native DLL for an LED controller. I provide examples in multiple languages. The callbacks are so you know when the device is plugged or unplugged. I use BeginInvoke so the callbacks are on the same thread as m_ctrl which is the main form.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS