I haven't tried this; but, again, I believe you cannot delete members of a
collection while iterating over it with the for-each statement. That is why
I chose the other solution I posted.
> For Each frm As Form In Me.MdiChildren
> frm.Close()
[quoted text clipped - 9 lines]
> >
> > WR
John - 10 Jul 2007 11:34 GMT
Hi,
The sample I gave you works fine.
It is interesting your point regarding whether or not you can
delete members of a collection while iterating over it with a
for each, I don't have a definative answer for that. Regardless,
that is not what is occurring in this case.
My code does the same thing as yours but is more concise and
more importantly the variables go out of scope after the for
next, thus helping to avoid a memory leak.
The key point here is that MdiChildren returns a new array. In
your code you are working against the array returned by
MdiChildren just like I am. Perhaps what you intended to do
was this:
Dim myforms() As Form
Me.MdiChildren.CopyTo(myforms, 0)
Dim i As Int16
For i = (myforms.Length - 1) To 0 Step -1
myforms(i).Close()
Next
The above is redundant because MdiChildren is already
making a copy of the internal array. Does that make sense or
is my understanding incorrect/incomplete?
Thanks.
J
>I haven't tried this; but, again, I believe you cannot delete members of a
> collection while iterating over it with the for-each statement. That is
> why
> I chose the other solution I posted.