Expression expected

The error is expression expected on line 12
  Private Shared Sub InitializeComPort(port As String, baud As Integer)
            ComPort = New SerialPort(port, baud)
            ComPort.PortName = port
            ComPort.BaudRate = baud
            ComPort.Parity = Parity.None
            ComPort.StopBits = StopBits.One
            ComPort.DataBits = 8
            ComPort.ReceivedBytesThreshold = 9
            ComPort.RtsEnable = True
            ComPort.DtrEnable = True
            ComPort.Handshake = System.IO.Ports.Handshake.XOnXOff
            AddHandler ComPort.DataReceived, += New SerialDataReceivedEventHandler(OnSerialDataReceived)<-------------HERE is error
        End Sub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
The format of the AddHandler statement is different from your line of code:

eg.  AddHandler Obj.Ev_Event, AddressOf EventHandler

You should have something like the following
AddHandler ComPort.DataReceived, += AddressOf OnSerialDataReceived
Éric MoreauSenior .Net ConsultantCommented:
have a look at this other question. It is handling the events:
AndyAinscowFreelance programmer / ConsultantCommented:
oops, didn't delete enough after copying your line of code:
AddHandler ComPort.DataReceived,  AddressOf OnSerialDataReceived
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Fernando SotoRetiredCommented:
Hi  r3nder;

Replace your line 12 with the following line
AddHandler ComPort.DataReceived, AddressOf ComPort_DataReceived

Open in new window

Then you need to create a event handler with the following signature.
Private Sub ComPort_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) 

    ‘’ Here you place your code to handle the received data

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r3nderAuthor Commented:
Thank you Mr Soto
Fernando SotoRetiredCommented:
Not a problem r3nder, glad to help.
AndyAinscowFreelance programmer / ConsultantCommented:
Any reason you didn't want to split between the other experts who pointed out exactly the same but rather earlier?
r3nderAuthor Commented:
No not really - got a notification checked the answer and awarded points accordingly
AndyAinscowFreelance programmer / ConsultantCommented:
OK.  I'll try to remember you award to the last person how posts not the first with the correct answer.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.