Convert C# to VB.Adding Eventhandler.

J

Jim Andersen

I have this piece of code I am trying to convert from c# to vb.net.
It's a Windows project.

This line gives me trouble ( I have tried to compress the code for
readability. Hope I haven't screwed up):
m_CA.AnEvent += new U.U_EventHandler(evt);

I assume this is a c# way of adding an additional eventhandler to an event?

If I move this over to VB, I get an error at "AnEvent", and at "evt"
The AnEvent error is "....Can't call directly. Use RaiseEvent...".
The evt error is "....use addressof..."

I don't know if the following information is useful.
At the top of the code is
private U.CC m_CA = null;

and then there is a sub with
m_CA = new U.CC();
m_CA.AnEvent += new U.U_EventHandler(evt);

And then there is this sub
private void evt(byte id, string data){......}

somewhere inside U is
public virtual event U_EventHandler AnEvent;

tia
/jim
 
P

Pritcham

I have this piece of code I am trying to convert from c# to vb.net.
It's a Windows project.

This line gives me trouble ( I have tried to compress the code for
readability. Hope I haven't screwed up):
m_CA.AnEvent += new U.U_EventHandler(evt);

I assume this is a c# way of adding an additional eventhandler to an event?

If I move this over to VB, I get an error at "AnEvent", and at "evt"
The AnEvent error is "....Can't call directly. Use RaiseEvent...".
The evt error is "....use addressof..."

I don't know if the following information is useful.
At the top of the code is
private U.CC m_CA = null;

and then there is a sub with
m_CA = new U.CC();
m_CA.AnEvent += new U.U_EventHandler(evt);

And then there is this sub
private void evt(byte id, string data){......}

somewhere inside U is
public virtual event U_EventHandler AnEvent;

tia
/jim

Hi

Something like "AddHandler m_CA.AnEvent, AddressOf evt" ?
 
H

Herfried K. Wagner [MVP]

Jim Andersen said:
I have this piece of code I am trying to convert from c# to vb.net.
It's a Windows project.

This line gives me trouble ( I have tried to compress the code for
readability. Hope I haven't screwed up):
m_CA.AnEvent += new U.U_EventHandler(evt);

\\\
AddHandler m_CA.AnEvent, AddressOf evt
///
I assume this is a c# way of adding an additional eventhandler to an
event?

'AddHandler'/'RemoveHandler' are supported by VB and work pretty similar.
In addition, VB supports 'WithEvent' declarations of type-level variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top