|
-
Aug 9th, 2012, 04:52 AM
#1
Thread Starter
Fanatic Member
Translate this from C# to vb
Sorry about the double post guys but not too many of the VB guys know c#. Then again maybe you guys know little about VB 
I have been given this example code to help solve a problem I'm working on but I need to convert it to VB which I know little about.
The various code convertors out there get it wrong.
Any ideas how VB handles this :
Code:
report.Error += delegate(object innerSender, ErrorEventArgs eventArgs)
{
this.ReportViewer.Report = null;
this.Label1.Text = eventArgs.Exception.Message.ToString();
};
Thanks In Advance
-
Aug 9th, 2012, 05:08 AM
#2
Re: Translate this from C# to vb
It doesn't. That's an anonymous method which is a C#-only feature. That said, anonymous methods have basically been superseded by lambda expressions in C# and they are supported in VB too. VB 2008 only supports value lambdas, i.e. functions, and even then only a single line of code is allowed, so you can only do that in VB 2010. In VB, you use the AddHandler statement to attach a handler to an event. You need to specify the delegate to attach, which you usually do by specifying the AddressOf the method that will handle the event. In VB 2010 you can also use an action lambda, i.e. a subroutine.
vb.net Code:
AddHandler report.Error, Sub(innerSender As Object, eventArgs As ErrorEventArgs) Me.ReportViewer.Report = Nothing Me.Label1.Text = eventArgs.Exception.Message.ToString() End Sub
You can in VB 2010 as well but in VB 2008 you would have no choice but to actually declare a regular named method and then use AddressOf to specify that as the event handler.
By the way, that use of ToString is pointless because the Message property of an exception is type String to begin with.
Last edited by jmcilhinney; Aug 9th, 2012 at 05:13 AM.
-
Aug 9th, 2012, 05:45 AM
#3
Thread Starter
Fanatic Member
Re: Translate this from C# to vb
Thanks jmcilhinney.
I shall give that a go and keep you updated.
-
Aug 10th, 2012, 03:47 AM
#4
Thread Starter
Fanatic Member
Re: Translate this from C# to vb
Thanks.
You are a God among men
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|