cementboot Posted November 19, 2006 Posted November 19, 2006 (edited) How can I refer to an form in array of forms? Hi, How can I refer to an form in array of forms? In my project, I have created an array of forms in a module like this: Module FormsArray Public ArrayOfForms(25) As clsDummyForm Public Sub CreateFormsArray(ByVal i As Integer) ArrayOfForms(i) = New clsDummyForm End Sub Public Sub CloseForms(ByVal i As Integer) ArrayOfForms(i).Close() End Sub End Module (clsDummyForm in the code above is a class in which I am inheriting System.Windows.Forms.Form) The problem occurs when I try to use the CloseForms() sub from another form like this: Public Class Form1 Private Sub CloseAllForms() For x As Integer = 1 To 25 CloseForms(x) Next End Sub End Class I get the error "Object is not set to an instance of an object". Any suggestions on how I can fix this? -thanks Edited November 19, 2006 by cementboot Quote
*Experts* mutant Posted November 19, 2006 *Experts* Posted November 19, 2006 First of all I would not suggest using Modules but that is a topic for another discussion ;). Are you sure you called the initialization sub for all the forms in your array? This error is most likely occuring due to not initialzing some form objects in the array and trying to use them. Quote
cementboot Posted November 19, 2006 Author Posted November 19, 2006 Mutant, thanks for your help! I think I figured it out now. I wasn't initializing all of the forms and therefore some of them had the value of nothing. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.