Replacing Data in an ArrayList

G

Guest

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

Barry Kelly

StumpedSteve said:
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
 
P

pvdg42

StumpedSteve said:
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.
 
G

Guest

That Worked! It's that darn first grade stuff that bites me all the time.

Thank you both for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top