|
Progress doesn't take a parameter, according to it's declaration. How did you resolve the fact that VB.NET lacks a "yield return" statement?
..and how about simply wrapping the C# code in an assembly and reference that from VB?
Bastard Programmer from Hell
|
|
|
|
|
From my initial message:Michael Schäuble wrote: In order to avoid problems with conversion of c# 'yield' operator, I put the extensions into a DLL and set a reference to that. According to IntelliSense 'progress' should be an integer value for 'percentProgress'.
The funny thing is that it works as described as long as I stay in C# with the Main procedure - also when using the same referenced DLL for all the extensions:
items
.WithProgressReporting(progress => worker.ReportProgress(progress))
.ForEach(item => Thread.Sleep(10));
Line 2 results in the percentage, which is properly reported to the console. So there really must be something wrong with the lambda, which obviously is too cryptic for me... Still this is exactly the part of the code which I can't reference (main procedure "TestProgressReporting") since my application is written in VB.
modified 1-Jan-12 18:42pm.
|
|
|
|
|
Eddy Vluggen wrote: How did you resolve the fact that VB.NET lacks a "yield return" statement?
perhaps with patience. Yield exists since VS2010 SP1 according to this[^].
And it is simply yield , not yield return , so for once VB.NET is less verbose than C#.
|
|
|
|
|
Hey Luc,
thanks for the hint, I'm just about downloading SP1. Still I'm afraid it wouldn't solve the problem I have: As I wrote I put all the extensions into a DLL which I'm referencing from my main VB code as well as from VB and C# test procedures. It seems pretty clear that there must be something wrong with the Lambda expressions. Would you have a look at them, please?
|
|
|
|
|
I seldom use lambda's, I probably can't help you.
If they are in a separate DLL, why aren't you using C# for them?
|
|
|
|
|
You misunderstood me. All the extension methods, which contain the C# 'yield' operator, are in a separate DLL. My application is in VB so I have to call the extensions from VB using adapted code... and the sample code (pls. see link in the initial message) is in C# where the Lambdas work.
|
|
|
|
|
Cool - I never missed the statement in VB, until this question popped up
Bastard Programmer from Hell
|
|
|
|
|
|
VB2010 has introduced sub(parameter) into the lambda specification. I haven't tested it but wouldn't the following work?
items.WithProgressReporting(sub(progress) worker.ReportProgress(progress) end sub).forEach(function(item) thread.Sleep(10)))
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Hi Simon,
sorry for the late response which was due to a short holiday of mine. Thanks for your hint which pushed me in the right direction: In the end, all I had to do was change "function" into "sub" in VB. It's finally solved now, and the line
items.WithProgressReporting(Sub(progress) worker.ReportProgress(progress)).ForEach(Sub(item) Thread.Sleep(10)) works, as well as Estys suggestion to factor out the subs. No "end" needed here.
Regards - Mick
|
|
|
|
|
Glad it helped
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Try changing this line:
items.WithProgressReporting(Function(progress)
worker.ReportProgress(progress)).ForEach(Function(item) Thread.Sleep(10))
To this:
items.WithProgressReporting(Function(progress) _
worker.ReportProgress(progress)).ToList.ForEach(Function(item) Thread.Sleep(10))
The .ForEach extension method doesn't work with IEnumerables and since that's what WithProgressReporting returns, the resultset must first be cast as a Generic List. Also, I don't know for sure, but it looks like the converter inserted an extra line break. That's why I added the underscore to the end of the first line.
modified 3-Jan-12 19:59pm.
|
|
|
|
|
Hi Member... ,
sorry for the late response which was due to a short holiday of mine. Thanks for your hint which unfortunately didn't work: In the end, all I had to do was change "function" into "sub" in VB. It's finally solved now, and the line
items.WithProgressReporting(Sub(progress) worker.ReportProgress(progress)).ForEach(Sub(item) Thread.Sleep(10)) works, as well as Estys suggestion to factor out the subs (no "end" or "ToList" constructions needed).
Regards - Mick
|
|
|
|
|
I always have trouble with anonymous delegates in VB so I factored them out :
Class Program
Shared worker As BackgroundWorker
Public Shared Sub Main()
worker = New BackgroundWorker()
worker.WorkerReportsProgress = True
AddHandler worker.DoWork, AddressOf DoWork
AddHandler worker.ProgressChanged, AddressOf ProgressChanged
worker.RunWorkerAsync()
Console.Read()
End Sub
Private Shared Sub DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim items = Enumerable.Range(1, 1000)
items.WithProgressReporting(AddressOf ReportProgress).ForEach(AddressOf DoSleep)
End Sub
Private Shared Sub ReportProgress(ByVal progress As Integer)
worker.ReportProgress(progress)
End Sub
Private Shared Sub DoSleep(ByVal item As Integer)
Thread.Sleep(10)
End Sub
Private Shared Sub ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
Console.SetCursorPosition(1, 0)
Console.Write(e.ProgressPercentage)
End Sub
End Class
Cheers
|
|
|
|
|
Hi Estys,
sorry for the late response which was due to a short holiday of mine. Thanks for your hint which, together with the other guys' ideas, pushed me in the right direction: In the end, all I had to do was change "function" into "sub" in VB. It's finally solved now, and the line
items.WithProgressReporting(Sub(progress) worker.ReportProgress(progress)).ForEach(Sub(item) Thread.Sleep(10)) works, as well as your suggestion to factor out the subs. Just to complete: In your snippet I had to change the definition of 'items' to:
Dim items As IEnumerable(Of Integer) = Enumerable.Range(1, 1000) in VB. But the most important thing: It works - and I hope I understand it a little better
Thanks again,
regards - Mick
|
|
|
|
|
Michael Schäuble wrote: I had to change the definition of 'items'
That's odd, with me it worked as I posted it.
I'm on .NET 3.5, VB Express 2008
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
In VB, a function that returns void is a "Sub". This is true with lambda function as well. So your ForEach lambda should be
ForEach(Sub(item) Thread.Sleep(10))
|
|
|
|
|
Only true with 2010 though, as there is many time I would loved to of used it in my current project that is 3.5 framework
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Hi David,
sorry for the late response which was due to a short holiday of mine. Thanks for your hint which pushed me in the right direction: In the end, all I had to do was simply change "function" into "sub" in VB. It's finally solved now, and the line
items.WithProgressReporting(Sub(progress) worker.ReportProgress(progress)).ForEach(Sub(item) Thread.Sleep(10)) works, as well as Estys suggestion to factor out the subs (slightly changed).
Thanks again,
regards - Mick
|
|
|
|
|
i create purchase and sales tables forms also a create
Excise from how to add purchase from sales from
Excise
Description: Details about Excise
FieldName Datatype Constraints Description
Exciseid Numeric(4) PK Excise id number
Purchaseid Numeric(4) PK, FK ID of purchase
Salesid Numeric(4) PK, FK ID od sales
Excisecode Numeric(4) Enter the Excise code
ExciseDate Datetime Datetime of excise
ple rpy me.
|
|
|
|
|
Excise
Description: Details about Excise
FieldName Datatype Constraints Description
Exciseid Numeric(4) PK Excise id number
Purchaseid Numeric(4) PK, FK ID of purchase
Salesid Numeric(4) PK, FK ID od sales
Excisecode Numeric(4) Enter the Excise code
ExciseDate Datetime Datetime of excise
|
|
|
|
|
My application is in VB6 and environment is Window XP. We are using WebBrowser control to display data of Word doc files i.e. we are opening word files always inside the WebBrowser control and then modifying word file using macros.Our application send email to user with body as word files i.e we paste word file data into email body part.Our VB code is perfectly working with office 2003 and office 2010.We are doing following changes in window registry via VB6 code for temporary basis:
1)..HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.Document.8\
updating BrowserFlags value to H80000024
2)..HKEY_CLASSES_ROOT\Word.Document.8\
updating EditFlags value to 65536
3)..HKEY_CLASSES_ROOT\Word.Template.8\
updating EditFlags value to 65536
4)..HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.Document.12\
updating BrowserFlags value to H80000024
5)..HKEY_CLASSES_ROOT\Word.Document.12\
updating EditFlags value to 65536
6)..HKEY_CLASSES_ROOT\Word.Template.12\
updating EditFlags value to 65536
Now we are migrating environment from WinXP to Win7. I have following query for Win7 environment :
1) Will we able to do registry changes using VB6 code on the all same path as mentioned above ?
2)Will Word doc files always open inside webBrowser control ?
3)Do we require additional registry changes for BrowserFlags and EditFlags via VB6 code ?
4)Please suggest us what else we have to do for registry changes and to send email ?
I have one more query .If Win7 support team does not give us rights to change registry then without changing values of BrowserFlags and EditFlags , how word docs files will open inside webBrowser control of VB6 ?
|
|
|
|
|
Your uses will not be able to modify anything under LOCAL_MACHINE or CLASSES_ROOT, so your questions are irrelevant.
You don't need a webbrowser control to open/edit/print Word documents. I suggest you Google for "VB6 Office Interop".
|
|
|
|
|
Will I able to open & modify word doc using VB6 Office Interop ?
|
|
|
|
|
What did I tell you to do?? Google it and find out. You might want to try "VB6 eidt Word document".
|
|
|
|