Visual Basic 6 Form

How can I tell if a form (other than the one I'm working on) is open or closed?

+2


source to share


3 answers


You must distinguish between Loaded and Visible .

  • For visiblility, just check the property Visible

    (noting that doing this for an unloaded form will load it).
  • Unfortunately, there is no property for the loading state. You have to loop over all the forms and see if your form is contained in the list of loaded forms:

    Public Function IsFormLoaded(FormToCheck As Form) As Boolean
      Dim F As Form 
      For Each F In Forms
        If F Is FormToCheck Then
          IsFormLoaded = True
          Exit Sub
        End If
      Next
    End Sub
    
          



The global collection Forms

contains all currently loaded forms.

+7


source


You can search the collection of forms



Dim aForm
For Each aForm In Forms
  If aForm Is Form1 Then
    MsgBox "Found Form1"
  End If
Next

      

+3


source


If the form is in your application, you can just keep track of its internal state. After all ... you control the points in your code when they can be created or destroyed.

+1


source







All Articles