Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All,
Below is some C# code that works:

C#
public Form1()
   {
          InitializeComponent();
      SerialPinChangedEventHandler1 = new SerialPinChangedEventHandler(PinChanged);
      myComPort.DataReceived +=
        new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived_1);
   }

What I'm trying to do is get this in VB form as below:

VB
SerialPinChangedEventHandler1 = New SerialPinChangedEventHandler(PinChanged)

ComPort.DataReceived += New System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived_1)

How do I attach event handlers in VB this is odd, getting pulled to other things now!


Glenn
Posted
Comments
Sergey Alexandrovich Kryukov 4-Feb-14 12:36pm    
What prevents you from just reading in VB.NET syntax?
—SA

Please refer this to understand how to add handlers

http://msdn.microsoft.com/en-us/library/6yyk8z93(v=vs.90).aspx[^]
 
Share this answer
 
Comments
glennPattonWork3 4-Feb-14 12:42pm    
Thanks
Here: http://msdn.microsoft.com/en-us/library/7taxzxka.aspx[^].

If some syntax seems odd to you (which I can understand), either use this odd way, or switch to the language which looks more syntactically reasonable to you. :-)

For future, do such a routine thing as translations between C# and VB.NET by yourself. I provided comprehensive explanations on how to do that automatically. And the off-line approach (using ILSpy) is the most reliable and gives you very good quality. Please see my past answers:
Need to convert vb code to c#[^],
Code Interpretation, C# to VB.NET[^].

—SA
 
Share this answer
 
Comments
glennPattonWork3 4-Feb-14 12:42pm    
I'm stuck it has to be VB!!
Sergey Alexandrovich Kryukov 4-Feb-14 14:36pm    
As you can see, I said "either". And provided you the reference to the "odd" syntax you can use. So, will you formally accept the answer (green "Accept" button)?
—SA
glennPattonWork3 4-Feb-14 17:20pm    
I did click it, but it turned red for reject solution! I think some thing has gone wrong!
Sergey Alexandrovich Kryukov 4-Feb-14 17:28pm    
How else? When "Accept" is done, the remaining option is "Reject". Isn't it logical? You've done all correctly already, thanks. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900