473,468 Members | 1,303 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Replacing Data in an ArrayList

I am working in VB.net and have a problem that I can’t seem to find any
information on. I have an arraylist that I’ve filled with positional data
from a {numerical control machine} program. I now need to rescan through the
array list and add values to two of the fields of my structure. I’ve setup a
for-each loop:

For Each strArray As Geometry In _Geometry

I can find the data and I can change the structure fields of strArray. I
use a messagebox to see that the data changed and it has. I’ve tried to use
_Geometry.remove(index) and then reinsert the line with _Geometry.insert.
I’ve tried to use “.Item” that is to be used to retrieve and set data but so
far nothing has worked. I thought that I could make another arraylist and
just transfer the data with the changes to it, but this may cause memory
problems if the data files are long. I don’t see a “replace” property. Each
time I get a:

An unhandled exception of type 'System.InvalidOperationException' occurred
in mscorlib.dll

Additional information: Collection was modified; enumeration operation may
not execute.

Thanks in advance for any help.

--
You don’t know everything you don’t know! Don’t you wish you’d paid better
attention in school?

Jul 14 '06 #1
3 1552
StumpedSteve <St**********@discussions.microsoft.comwrote:
For Each strArray As Geometry In _Geometry
You can't modify a collection that you're iterating over with for-each.
Use a 'For' loop instead.

-- Barry

--
http://barrkel.blogspot.com/
Jul 14 '06 #2

"StumpedSteve" <St**********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
>I am working in VB.net and have a problem that I can't seem to find any
information on. I have an arraylist that I've filled with positional data
from a {numerical control machine} program. I now need to rescan through
the
array list and add values to two of the fields of my structure. I've
setup a
for-each loop:

For Each strArray As Geometry In _Geometry

I can find the data and I can change the structure fields of strArray. I
use a messagebox to see that the data changed and it has. I've tried to
use
_Geometry.remove(index) and then reinsert the line with _Geometry.insert.
I've tried to use ".Item" that is to be used to retrieve and set data but
so
far nothing has worked. I thought that I could make another arraylist and
just transfer the data with the changes to it, but this may cause memory
problems if the data files are long. I don't see a "replace" property.
Each
time I get a:

An unhandled exception of type 'System.InvalidOperationException' occurred
in mscorlib.dll

Additional information: Collection was modified; enumeration operation may
not execute.
For Each is read only.
Jul 14 '06 #3
That Worked! It's that darn first grade stuff that bites me all the time.

Thank you both for your help.
--
You don’t know everything you don’t know! Don’t you wish you’d paid better
attention in school?

"pvdg42" wrote:
>
"StumpedSteve" <St**********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
I am working in VB.net and have a problem that I can't seem to find any
information on. I have an arraylist that I've filled with positional data
from a {numerical control machine} program. I now need to rescan through
the
array list and add values to two of the fields of my structure. I've
setup a
for-each loop:

For Each strArray As Geometry In _Geometry

I can find the data and I can change the structure fields of strArray. I
use a messagebox to see that the data changed and it has. I've tried to
use
_Geometry.remove(index) and then reinsert the line with _Geometry.insert.
I've tried to use ".Item" that is to be used to retrieve and set data but
so
far nothing has worked. I thought that I could make another arraylist and
just transfer the data with the changes to it, but this may cause memory
problems if the data files are long. I don't see a "replace" property.
Each
time I get a:

An unhandled exception of type 'System.InvalidOperationException' occurred
in mscorlib.dll

Additional information: Collection was modified; enumeration operation may
not execute.
For Each is read only.
Jul 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: notalent | last post by:
I'm having a problem with a very basic program. I'm creating a app in Visual Studio (2003) C# to zip up a collection of specified files & directories and save them to a certain location. I have...
8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
0
by: si | last post by:
I'm very new to using C# in an ASP.NET application, and am used to using the ADO GetRows() method to quickly dump data into a multidimensional array in classic ASP. I am trying to work through...
1
by: davehunt | last post by:
Hi folks, New C# programmer here. I am reading some CSV data from a file into an ArrayList. I want to get the data from the ArrayList into a 2-dimensional array. I see a few references to...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
9
by: shadow.demon | last post by:
G'day, I've separated my database calls into a separate dll, and return results from any database calls as a SqlDataReader (because of SQL Server use, it's nice and fast). However I'd like to be...
9
by: Ben R. | last post by:
Hi guys, I've got a DB table of timecards with these fields in the table: ID (Int) UserID (Int) DateWorked (DateTime) HoursWorkedOnThatDate (Double) I'd like to display a grid, with...
1
by: ajos | last post by:
Hi friends, In my class i have a ArrayList where i have stored the resultset data from the and also a float value i.e ive 2 arraylist. The way ive set the data is-- list.add(getData(resultset));...
1
by: =?Utf-8?B?SkI=?= | last post by:
Hello My pgm1 (User Interface Level) passes an empty ArrayList to pgm2 (Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to populate the ArrayList. Question1: When pgm2 gets...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.