I'm trying to use the following code to iterate over all of the currently open forms in my application and close them except for the main form as part of a clean up.
Dim openForms As Windows.Forms.FormCollection = Application.OpenForms
For Each frm As Windows.Forms.Form In openForms
If frm.Name.ToString() <> "FrmMainNew" Then
Iterate backwards so that modifying the collection doesn't byte:
For ix As Integer = Application.OpenForms.Count - 1 To 0 Step -1 Dim frm = Application.OpenForms(ix) '' etc.. Next