Replacing Data in an ArrayList

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
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.
 
That Worked! It's that darn first grade stuff that bites me all the time.

Thank you both for your help.
 
Back
Top