Print Page | Close Window

new user question

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1728
Printed Date: 21-Apr-2026 at 3:52pm


Topic: new user question
Posted By: iosub
Subject: new user question
Date Posted: 20-Apr-2010 at 8:20am
Hi
I'm learning :-)
 
how do you convert c#

query.ExecuteAsync(op => op.Results.ForEach(Employees.Add));

 
to VB.net??
 
Thanks!
 
Btw.. any chance to have VB examples??
 
 



Replies:
Posted By: ji
Date Posted: 20-Apr-2010 at 10:12am
Hi,
 
you can find online tools to do the conversion  job by searching "convert c# to vb "...
 
 


Posted By: iosub
Date Posted: 20-Apr-2010 at 10:14am
Hi
 
already try... none of them converts correctly
 
I have try with " http://www.developerfusion.com/tools/convert/csharp-to-vb/ - http://www.developerfusion.com/tools/convert/csharp-to-vb/ "

http://www.carlosag.net/Tools/CodeTranslator/ - http://www.carlosag.net/Tools/CodeTranslator/  

 

do you know any better?

 

Thanks!



Posted By: davidklitzke
Date Posted: 20-Apr-2010 at 10:36am
Have you tried Instant VB?


Posted By: iosub
Date Posted: 20-Apr-2010 at 10:56am
Yes.
 
all convertes translate it to

query.ExecuteAsync(Function(op) op.Results.ForEach(Employees.Add))

gives error:
Error 1 Overload resolution failed because no accessible 'ExecuteAsync' can be called with these arguments:
Error 3 Lambda parameter 'op' hides a variable in an enclosing block, a previously defined range variable, or an implicitly declared variable in a
 
 
I'm lost :-(


Posted By: iosub
Date Posted: 20-Apr-2010 at 12:16pm
Hi
 
No more help??
 
Thanks!


Posted By: davidklitzke
Date Posted: 20-Apr-2010 at 1:56pm
Are you using .NET 3.5 or .NET 4.0?
 
In .NET 3.5, there are differences between what you can do in a C# Lamda and what you can do in a VB.NET Lamda.  For example, in a C# Lamda, the Lamda may or may not return a value.  In VB.NET, the Lamda MUST return a value.  Many of the differences in capability are supposed to be remedied in .NET 4.0.
 
Here is one link that talks about some of the differences in C# and VB.NET Lamdas in .NET 3.5.
 
http://msmvps.com/blogs/deborahk/archive/2009/10/11/lambda-expressions-action-delegates.aspx - http://msmvps.com/blogs/deborahk/archive/2009/10/11/lambda-expressions-action-delegates.aspx
 
 


Posted By: iosub
Date Posted: 20-Apr-2010 at 2:48pm

Hi

I'm using net4 (devforce 2010)
 
I have try with also with "query.ExecuteAsync(Sub(op) op.Results.ForEach(Employees.Add)) "

error

Error 1 Overload resolution failed because no accessible 'ExecuteAsync' can be called with these arguments ..

 
I could not think that this was so hard... :-(
 
do you have on ideablade code examples on VB.net??
 
Thanks
Iosu


Posted By: WardBell
Date Posted: 20-Apr-2010 at 7:12pm

Hi Iosu -

Sorry about the delay and imprecision in our replies. VB is not our first language and we struggle a bit. VB 10 in .NET 4 is new to us. We like the improvements ... but it will take some getting used to.

In VB 9, one could not write "statement lambdas". Now you can. I don't think the conversion tools have caught up.

So I'm going to show you a few ways you could write the query you have in mind.

Please note that the "ForEach" is a DevForce-provided extension method on IEnumerable; it's located in IdeaBlade.Core.EnumerableFns. You have to add the Import.

In all of the following examples, I assume

  Imports DomainModel
  Imports System.Collections.Generic
  Imports IdeaBlade.EntityModel
  Imports IdeaBlade.Core

  ...
 
  Dim employees As New List(Of Employee)
  Dim query = mgr.Employees ' mgr is an EntityManager instance

Here is the one statement that is closest to the C# expression you mentioned:

  query.ExecuteAsync(Sub(op) op.Results.ForEach(Sub(r) employees.Add(r)))
 

You almost had it!   You would have figured this out had we written the C# as
 
  query.ExecuteAsync(op => op.Results.ForEach((r)=> employees.Add(r)))
 
We took advantage of the C# compiler's ability to translate the method group, "Employees.Add", into the equivalent of "Sub(r) employees.Add(r))". That's what let us write:
 
  query.ExecuteAsync(op => op.Results.ForEach(employees.Add))
 
VB has some other nice tricks but it doesn't have this one :-)
 
--
 
If you don't like our ForEach extension method, you could write  the query as:

  query.ExecuteAsync(
      Sub(op As EntityQueryOperation(Of Employee))
        For Each emp In op.Results
          employees.Add(emp)
        Next
      End Sub)

--

DevForce also offers an alternative syntax that is more "event oriented."

The ExecuteAsync returns an EntityQueryOperation(Of T) object that has a "Completed" event. You can handle that instead of relying on the callback. The "Completed" handler receives an "EntityQueriedEventArgs(Of T)".

  Dim qop = query.ExecuteAsync()

  AddHandler _
    qop.Completed,
    Sub(sender, args)
      args.Results.ForEach(Sub(r) employees.Add(r))
    End Sub

--
 
Once again, should you prefer to do write the "For Each" yourself, you could say:

  Dim qop = query.ExecuteAsync()

  AddHandler _
    qop.Completed,
    Sub(sender, args)
      For Each emp In args.Results
        employees.Add(emp)
      Next
    End Sub

--

Important note: we do not show exception handling in these examples. Error information is available both from the Operation object (which is passed into the callback) and in the EntityQueriedEventArgs.  Production code would check for errors.

Hope this helps.

 


Posted By: iosub
Date Posted: 21-Apr-2010 at 5:05am
HI
 
Yes you are right I was getting with a bad imprecision.. Don't worry I understad that VB is not your first language (I'm bask so English is not my first language also :-) )
 
Ok,I was traying yesterday all day for a solution.. And these are my conclusions...
 
1.- The intelissence of vb is not working correctly with ".ForEach"
when you write the :

query.ExecuteAsync(Sub(op) op.Results (when you push "." ) does not show up the "ForEach" on the list so I thought that it was not the right way to do.. Instead I writed this:

query.ExecuteAsync.Results.ForEach(Sub(o) employees.Add(o)) witch does show ForEach on the list but it does not load data.
 
Now with:
query.ExecuteAsync(Sub(op) op.Results.ForEach(Sub(r) employees.Add(r))) it works!

 

My conclusions for VB.Net Users and Ideablade.

1.- Ideablade makes the tutorials in VB.net also
2.- Ideablade makes the C# code as close as posible to VB.Net, without using C# compiler "compiler's ability " or tricks.. So for VB.net programer is much easy to translate c# to Vb.net (also converters).
 
Thank you for your help.
 
 
Iosu
 
Btw...
 
the C:\Users\Public\Documents\DevForce 2010\Learning Resources\030_BaseApps\SilverlightApps\Tutorials\100SLV_Tour\CodeCS\Tour_Pt01Completed\SimpleSteps does not load the data when run...
And C:\Users\Public\Documents\DevForce 2010\Learning Resources\030_BaseApps\SilverlightApps\Tutorials\100SLV_Tour\CodeCS\Tour_Pt02Completed DOES load but only when I click on Next Record on the DataForm
 
 
 

 



Posted By: WardBell
Date Posted: 21-Apr-2010 at 11:05am
Thanks for your understanding and your patience, Iosu.
 
We do care about our VB community and we will catch up.
 
I realized too late that there is a VB analog to the "method group" syntax we wrote in C#. It is as follows:

    ' The VB way to use "method group" syntax
    Return query.ExecuteAsync(
      Sub(op) op.Results.ForEach(AddressOf employees.Add))
 
This is not new to C# 4 / VB 10.  The VB translation of method group syntax has "always" been to prefix it with "AddressOf". 
 
The method group syntax is tidy in C# ... and I wouldn't want to distort C# coding practice in any case.
 
But I think the VB translation isn't that bad. VB will always be "more wordy" than C#; you like that ... or you don't. The differences have pretty much come down to this particular point of preference.
 
--
 
I'm not having trouble with VB Intellisense on ForEach. It gives the proper information ... when you remember to say "AddressOf". If you don't, it presents an ugly, unhelpful message about "ambiguity". That's just the way the VB compiler handles extension methods I guess. I don't know what to say. Not sure C# is much better either.
 
Happy coding.
 
 


Posted By: iosub
Date Posted: 21-Apr-2010 at 11:14am
Hi..
 
Thanks again for the support.. I keep evaluation your product.. Looks promising :-)
 
remember this also:
 
 
 
the C:\Users\Public\Documents\DevForce 2010\Learning Resources\030_BaseApps\SilverlightApps\Tutorials\100SLV_Tour\CodeCS\Tour_Pt01Completed\SimpleSteps does NOT load the data when run the application
 
And C:\Users\Public\Documents\DevForce 2010\Learning Resources\030_BaseApps\SilverlightApps\Tutorials\100SLV_Tour\CodeCS\Tour_Pt02Completed DOES load but only when I click on Next Record on the DataForm
 
I don't think is my mistaque... so better if you checkit so the learning course is good :-)
 
 
Iosu
 


Posted By: WardBell
Date Posted: 21-Apr-2010 at 12:54pm
Thanks, Iosu.
 
We are aware that "Simple Steps" does not load the data until you push the button. Very unfriendly. We will address it.


Posted By: iosub
Date Posted: 26-May-2010 at 5:11am
Originally posted by WardBell

Thanks, Iosu.
 
We are aware that "Simple Steps" does not load the data until you push the button. Very unfriendly. We will address it.
Hi, I have download DevForce2010RC2alpha and this problem is not fixed yet.. Do you know a workaround?? Or is going to be fixed on next Rc2 Drop??
 
 
Thanks!


Posted By: WardBell
Date Posted: 26-May-2010 at 12:08pm
We address it in "Part 4" where we fix this and a few other "issues" in our first pass design. Code and video for Part 4 are already to load to the web. Haven't written the doc for it yet but the video is pretty clear about what to do ... at least I think so.
 
Here's a sneak preview of the videos: http://www.ideablade.com/Videos/DevForce2010DevelopersTour/ - http://www.ideablade.com/Videos/DevForce2010DevelopersTour/


Posted By: iosub
Date Posted: 26-May-2010 at 3:31pm
Originally posted by WardBell

We address it in "Part 4" where we fix this and a few other "issues" in our first pass design. Code and video for Part 4 are already to load to the web. Haven't written the doc for it yet but the video is pretty clear about what to do ... at least I think so.
 
Here's a sneak preview of the videos: http://www.ideablade.com/Videos/DevForce2010DevelopersTour/ - http://www.ideablade.com/Videos/DevForce2010DevelopersTour/
 
 
Ward.... FANTASTIC VIDEO!!!!!! you got an "A" :-) really usefull.. Great Job!!
Thank you!!!
 
 
Is code avaible? or is part of the Rc2Alpha??? (I don't have the dev computer here..)
 
 
 
Btw...
 
I have move to C# :-)
Is on the video the Intellysense so diferent because the "reSharper"??? do you think is a good tool to buy?
 
 



Print Page | Close Window