简体   繁体   中英

C# to VB.net convertion error

I am trying to use MIDI.NET in Visual Basic 2010 while it is written in C#. So I got the tip to convert it using an online converter since these languages are quitte similair to eachother. The one problem I have is this line

inputDevice.NoteOn += new InputDevice.NoteOnHandler(NoteOn);

converted to vb.net it looks like this

InputDevice.NoteOn += New InputDevice.NoteOnHandler(NoteOn)

which gives me 2 errors.

  1. 'Public Event NoteOn(msg As NoteOnMessage)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\\Users\\Den Houting\\AppData\\Local\\Temporary Projects\\MIDI\\Form1.vb 14 9 MIDI

  2. Error 3 Delegate 'Midi.InputDevice.NoteOnHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor. C:\\Users\\Den Houting\\AppData\\Local\\Temporary Projects\\MIDI\\Form1.vb 14 82 MIDI

When trying to do something like RaiseEvent NoteOn it tells me NoteOn isn't an event.

Thanks.

The proper syntax in VB.NET uses AddHandler to register the event

AddHandler InputDevice.NoteOn, AddressOf NoteOn

More on MSDN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM