I have searched high and low for documentation on how to use this feature. While the loop I could write would be simple and take no time, I really would like to learn how to use this. Basically I have a class, say, Widget, with a Save() sub that returns nothing. So:
Dim w as New Widget()
w.Save()
basically saves the widget. Now let's say I have a generic collection List(Of Widget) name widgetList(Of Widget) and I want to run a Save() on each item in that list. It says I can do a
widgetList.ForEach([enter Action(Of T) here])
....but how in the F does this work??? There is no documentation anywhere on the intrablags.
I have a custom list that inherits Generic.List and it has a method for deselecting all of the members named DeselectAll It has looked like this for a few weeks and has worked fine.
Public Sub DeselectAll() MyBase.ForEach(Function(p As Publipostable) p.ModeEnvoiChoisi = Nothing) End Sub
Today, it stopped working ?!? I reverted to an earlier version using delegates and that works fine...
Public Sub DeselectAll() MyBase.ForEach(AddressOf DeselectModeEnvoi) End Sub
[code]....
Edit: Stopped Working meaning it no longer sets the property p.ModeEnvoiChoisi to Nothing on each item in the list. The DeselectAll method gets called, but all the items retain their previous values...
However it always returns 0. I've checked and the GetPartCost function executes and returns a non-zero number but the list item cost properties are never updated.The property is just a simple property,
Public Property Cost() As Double Get Return _Cost[code]....
If I set a breakpoint in the Set of the property, it never gets hit.
Here's the code I have but I'm getting syntax issues:
CODE:
I'm just looking to call ReadAndPopulate method for each item in aList. I know I can do it the traditional "For each a in aList...Next" way but wanted to learn how to do it with delegates.
Is it possible to pass multiple arguments to a delegate method from a list(Of T).ForEach call?So, I'd like to pass a listbox object to the delegate routine below:
Sub test() Dim names As New List(Of String) names.Add("Bruce") names.Add("Alfred")
I hope this question is sufficiently clear I'm trying to port an application that I wrote in Access VBA to VB 2010 express and SQL Server. In Access, when the user enters an item in a combobox that is not in the item list an event is fired ("not in list") from which I can set up records in related tables. How can I do the same in VB? I can't see any equivalent to the "not in list" event.
To be more explicit with an example. An address consists of Street, e.g. "23 Acacia Drive", Town, e.g."Wilton" and County, e.g. "Oxfordshire". When entering a new address, the form first requires a street entry in a text box. Next, a Town entry in a combo box which is populated with towns already in the address table. If an existing Town is selected the (previously disabled) County field is automatically filled from that town's County as read from the database. If a new Town is entered the County field is enabled and the user either selects an existing County or adds a new one which is added to the database using similar logic on the not in list event.
a datacontext defined in a module(domain services ado.net ria)a page having add/delete methods whenever any method is executed, it is found that all the previous actions (NEW RECORD ADDITION and DELETION OF RECORDS) are carried out before the new action is carried out normally
this behaviour is not prominent but "when using break points and inspecting the values of the variables and table object to be added to context, it is clear that all the previous actions take place again. even when the datacotext. savechanges is called, even after that still all actions carried out on the datacontext repeat themseleves, when any new action is to be carried out
My co-worker said that in a previous interview, he learned that foreach is faster in VB.Net than c#'s foreach. He was told that this was because both have different CLR implementation.
Coming from a C++ perspective, I'm curious on why this is and I was told that I need to read up on CLR first. Googling foreach and CLR doesn't help me understand.
Does anyone have a good explanation on why foreach is faster in VB.Net than in c#? Or was my co-worker misinformed?
I'm writing a loop to go through the first array of a 2D loop, and I currently have it like this:
For Each Dir_path In MasterIndex(, 0) 'do some stuff here Next
But it's giving me an error, saying it expects an expression in the first field. But that's what I'm trying to do, loop through the first field. How do I fix this? What would I put in there?
EDIT: to clarify, I'm specifically looking for the 0th element in the subarray of each array, that's why that second field is constantly 0.
What i'm doing is getting values from some html, i use a regex to retrieve all the fields, but there are some fields brought back i don't need (4 out of 11) i know the names of these fields, but was wondering if there was a way i could filter out the ones i don't need in the foreach:[code]
I recently changed a For Each loop to a Parallel.ForEach loop. I'm concerned about an object being declared outside the loop but assigned while iterating in the loop. Here is the simplified code.
Dim results As ModelResults Dim noResultsModel As New List(Of ModelResults) Dim lock As New Object Parallel.ForEach(_modelEngines, Sub(model)
[Code]...
Is there a potential race condition with the results object? Would anything be different if I moved the declaration of results into the for loop?
I'm flummoxed I'm using VB.Net, Linq, and a DataContext. My DataContext contains a table 'transactions'.
I first declare an IQueryable(Of transaction) and assign it to nothing. I build a predicate in a foreach loop and use a transactions.Where(predicate) to assign the IQueryable a value. If I do an IQueryable.ToList(), I get a number of items in the collection.
However, on the next iteration of the loop, the IQueryable.ToList() gives me 0 items.This is driving me crazy. I tried to use the LINQ to SQL Debug Visualizer with VS2010, (I recompiled the 2008 version with the new reference) but no dice - I can't see the SQl generated or what's inside the IQueryable.
I am making a program that automates the seperation of a csv file. We read the csv in through and then assign the "line" using a split command to an array. After that we go through each "cell" in the array and put an = in front because this causes leading zeros not to be lost. Here's the code.
arLine = line.Split(replace) For Each cell As String In arLine cell = cell.Replace(",", "") cell = String.Format(cellFormat, cell) Next
arLine is the array and replace is the delimiter, in this case a pipe not that it matters.'
When it goes through, the arLine is correct but the values in each cell are not changing, any thoughts? newer to VB.net and need direction
I am having an issue extracting the value from every row in column "MobileID" within a table named "dt" that is within a dataset named "ds".Here is how the dataset and datatable are created.[code]
I have the following for each loop which loops through a registry key and reads all the values:
Dim returnValue As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionRun") Dim keyname As String = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun" Dim values() As String = returnValue.GetValueNames
[code].....
What I am trying to have been highlighted in bold.. Each time the loop executes and reads a value from the registry, I want the code to create a checkbox which has a unique name and text according to the value that was read... So the number of checkboxes will depend on number of values that is got from the registry...But this doesn't work. It only creates one text box and the text of the textbox is also incomplete...
Everything is working fine except for one part. The part where the second foreach loop runs. If I only have one plugin installed it puts 2 entries in the list. The reason is because it has 2 rows and it is adding it twice. I know what the issue is I just am drawing a blank right now.
I've been trying to follow the examples I've found online and, well, I can't really get my head around what I've done wrong.So, I have a simple piece of code to search for a machine in AD, as so. [code]
I can't seem to get the syntax right for a simple Parallel.Foreach Loop.
This is how I would normally iterate a SearchResultCollection
Dim src As SearchResultCollection = DSearch.FindAll For Each x As SearchResult In src Debug.WriteLine(GetProperty(x, "Name")) 'Parallel.ForEach(x, Function(x) Debug.WriteLine(x)) Next
As I have (obviously) misunderstood it this should be the syntax for the Parallel.Foreach
Parallel.ForEach(src, (Sub(x As SearchResult) GetProperty(x, "Name"))) Parallel.ForEach(src, Function(x) Debug.WriteLine(x)) It's not that though. What's the correct syntax here?
I have a form called frmMapViewer. In this form I 25 labels showing districts of my country. think I want to assign names(text property) to each label.[code]...
Why there is only a static/shared version of ForEach for arrays? IE: ForEach<T>(T array[], System.Action(Of T) action[]) I assume this has something to do with the type inference requirements of implementing an instance method, but when you declare your array you provide type right?
How to write xml foreach datarow in dataset? I have dataset with 5 record in table, i want write to xml file with 5 xml file. in one xml file have one record.