Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by cementboot
  • *Experts*
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...