Iterating A List With ForEach

Mar 1, 2010

I have a list like this

[Code]...

How can I iterate the list with ForEach to get one string with the emails like this [URL]

View 5 Replies


ADVERTISEMENT

.net - Action(Of T) In VB In List(Of T).ForEach?

May 21, 2009

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.

View 5 Replies

Iterating List To XML?

Jun 24, 2011

I am trying to write XML that looks like this. It works so far, but when I get to the <rooms> node I can only output one.

<house>
<id>1</id>
<rooms>Living</rooms>

[code].....

View 10 Replies

Update Property Of Object In List In ForEach?

Apr 2, 2011

I have a List(Of SomeObject) that I enumerate over using a For Each loop. This SomeObject contains a Property that references another Object, as such

Class SomeObject
Public Property Another As AnotherObject
Get

[Code]....

If not, what is a valid way to do it? (ordinary for loop perhaps?)

View 1 Replies

.net - Iterating Through Generic List Of String?

Jan 28, 2012

I have the follow code in my program where I hit a SQLCe database to append the results into a list. That part works, but instead of exiting the function 'QueryDB' it goes to the else statement and runs the function again, which will return a null value. I designed it this way becuase I wanted to check to make sure the database is open before I try to execute the SQL statement, and if it's not open, call the method to open it and run through the function again.

[Code]...

View 1 Replies

.net - Generic List Extension Method ForEach Stopped Working?

Dec 16, 2010

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...

View 1 Replies

Using List(Of T).ForEach Method To Update Values Not Working As Expected?

Aug 8, 2011

I have the following code,

PB.ForEach(Function(x) x.Cost = GetPartCost(x.PartNumber, x.Units, x.Cost, FB))

Return PB.Sum(Function(x) (x.Cost * x.Qty))

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.

View 1 Replies

List.ForEach(Delegate) Call ReadAndPopulate Method For Each Item In AList

Jun 29, 2011

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.

View 8 Replies

Pass Multiple Arguments To A Delegate Method From A List(Of T).ForEach Call?

Sep 6, 2011

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")

[code]....

View 4 Replies

Foreach In Faster Than In C#?

Mar 12, 2009

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?

View 5 Replies

How To Use Parallel.ForEach

Apr 15, 2010

tell how to form this to the correct Syntax?ere the sample in sequential form:ForEach ctrl AsCheckBoxIn tblCKBoxCollection.Controlsctrl.Checked =

View 1 Replies

Anonymous Methods In .NET - Foreach?

May 16, 2011

I try to replace the classic For Each with the LINQ ForEach method in VB.NET

Dim singles As New List(Of Single)(someSingleList)
Dim integers As New List(Of Integer)
For Each singleValue In singles

[code]....

How should I correctly do it (using anonymous methods = without declare a new function)?

View 2 Replies

Foreach - Each Loop On A 2D Array In .NET

Oct 14, 2011

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.

View 2 Replies

VS 2008 - Using 2d Array With Foreach

Aug 24, 2010

is it possible to use foreach with a 2d array?

View 8 Replies

VS 2008 Getting Certain Info In Foreach

Aug 30, 2009

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]

View 5 Replies

.net - Parallel.ForEach Local Storage?

Aug 3, 2010

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?

View 1 Replies

.net - Unexpected IQueryable Value After ForEach Iteration?

Apr 15, 2012

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.

[Code]...

View 2 Replies

Changing The Value Of An Array Through A Foreach Statement?

Jun 13, 2012

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

View 2 Replies

Convert Collection.foreach From C# To Program?

May 12, 2009

In C# i just put the method in the parentheses that i want to run on each row of the collection, but it isn't working in VB.NET.[code]...

View 1 Replies

DataGrid View Creation Via ForEach

Apr 18, 2012

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]

View 1 Replies

Dynamically Add Checkboxes In A Foreach Loop?

May 8, 2009

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...

View 7 Replies

VS 2008 - Second Foreach Loop Runs

Jul 9, 2009

I have the following Method:

CODE:

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.

View 11 Replies

VS 2010 First Attempt At Parallel.ForEach

Apr 16, 2010

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]

View 5 Replies

VS 2010 Use Paralell.ForEach With A SearchResultCollection?

Oct 18, 2010

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?

View 13 Replies

[2008] Foreach Variable Undeclared?

Mar 9, 2009

i'm using a foreach to loop through my regular expression like:

For Each secwordMatch As Match In secwordmatches
Dim secWord As String = secwordMatch.ToString
Next

[code].....

View 4 Replies

.net - Linq To XML Not Iterating?

Feb 24, 2011

I have an XML file, with a rather large structure. I'm pulling several entities out of it throughout several systems, and its dynamically updated once a day. I'm using a Linq Query that is exhibiting odd behavior, its only returning if the first entry in the site tag matches the search-pattern. If its number 2 or 3, it fails to return anything. Why would this behave that way?

The following function written in VB handles pulling the data

Public Function xmlSchoolListBySite() As IEnumerable
Dim doc As XDocument = loadXML()
Dim loadedPrograms As IEnumerable(Of XElement) = From c In doc.Descendants("Organization") _
Where c.Descendants("site").Value = MySite.Site.s_Url _ 'contains Result.RawURL.tostring() formatted
Select c.Element("Title")

[Code]...

View 1 Replies

Iterating Through 2 Arraylists?

Jan 5, 2010

I have two arraylists that contains links in one and the root url in the other. Sometimes the lists dont equal in number and I would like to iterate through the links list and if it contains a matching root url add it to a third list but also avoid any duplicates. I tried this but am not getting consistent results.

For Each link As String In urls
For Each part As String In post
If part.Contains(link) Then

[code]....

Perhaps there is another way; basically the part in post is a link to a page and contains the root url( which is link in urls). After extracting all these I need to ensure the 2 lists match.

View 7 Replies

Iterating Through Datagridview By Row

Feb 10, 2012

I am iterating through rows in a datagridview in the following manner

[Code]...

Why are the column methods and properties not all available in this manner to set individual datagridview cells properties? The only options available for the variable,

View 1 Replies

Access Label Of Form In ForEach Loop?

Apr 8, 2009

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]...

View 5 Replies

C# - Why Only Static / Shared Version Of ForEach For Arrays

Aug 18, 2011

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?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved