S said:
if i declare a new form in the class, and button one does
"form2.show" and button2 does "form2.close", clicking form1.show
again causes an error because the form doesnt exist anymore. how can
i deal with this?
Two suggestions:
1. Get Button2 to hide the form rather than close it. You can hide and
re-show a form as many times as you like. It will of course be the same form
instance each time, so all values that were present in the form when you
hide it will still be there when you re-show it.
2. Alternatively, in Button2, after you close the form, set its reference to
Nothing. Then in Button1 you can check for this and create a new form if
required:
\\\
Public secondForm As Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If secondForm Is Nothing Then
secondForm = New Form2
End If
secondForm.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If secondForm IsNot Nothing Then
secondForm.Close()
secondForm = Nothing
End If
End Sub
///
HTH,