as the title, I am trying to close all open forms except some in VB.Net but the forms don't close. Here is the code I used:
Dim lista As New FormCollection
lista = Application.OpenForms
For Each a As Form In lista
If Not a.Text = "formLogout" And a.Text = "arresto" And a.Text = "riavvio" And a.Text = "formOpen" Then
a.Close()
End If
Next
scrivania.Close()
Me.Close()
Grazie.
Ifstatement will return true when all provided conditions are true, which is not possible because you compare sameform.Textwith different values.Notice that in your example
Notwill be applied only for the first conditionYou possibly can rewrite condition as follow:
Suggest to use a collection of form names, which should not be closed