Problem with converting code
from C# to VB. I have the code working fine in C#.
C#
Code:
interceptor = new MessageInterceptor();
interceptor.InterceptionAction = InterceptionAction.NotifyAndDelete;
interceptor.MessageReceived += new MessageInterceptorEventHandler(OnSmsReceived);
VB
VB Code:
interceptor = New MessageInterceptor()
interceptor.InterceptionAction = InterceptionAction.NotifyAndDelete
interceptor.MessageReceived += New MessageInterceptorEventHandler(OnSmsReceived)
I get errors in VB on line 3 saying I have to use a RaiseEvent statement for MessageRecevied. I am not sure how to do this if anyone can help.
Thanks
Re: Problem with converting code
If we as software developers cannot consult help documentation how can we expect our users to do so?
http://msdn2.microsoft.com/en-us/library/fwd3bwed.aspx
Re: Problem with converting code
Yeah thanks. I did actually look at some documentation but still don't understand how to do it. I understand that because MessageReceived is an event you have to RaiseEvent it rather that call it directly, so I would therefore put the RaiseEvent infront of it. I'm still doing something wrong though.
Re: Problem with converting code
The short-form VB equivalent is:
AddHandler interceptor.MessageReceived, AddressOf OnSmsReceived
You could also code:
AddHandler interceptor.MessageReceived, New MessageInterceptorEventHandler(AddressOf OnSmsReceived)
Re: Problem with converting code
So it's just like when you create a control at run time and you want to use its Click event for instance.
Is this the same as Raising and event then?
Thanks very much
Re: Problem with converting code
No - the original C# code you posted does not raise an event. It wires up the event handler.
Re: Problem with converting code
Hmmm... I guess I could have read the code too. :blush: Odd that it would point you to RaiseEvent when you're trying to handle an event rather than raise one. The page I linked to does include a link to the AddHandler statement and MSDN also includes pages many topics dedicated to raising an handling events.
http://search.msdn.microsoft.com/sea...andling+Events