473,418 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

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 1550
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.