Visual Basic 6 form

Tag: vb6 Author: haobinbin888 Date: 2009-09-25

How can I know that the form (other than the one I'm working upon) is open or closed?

Other Answer1

You have to distinguish between Loaded and Visible.

  • For visiblility just check the Visible property (noting that doing so for an unloaded form will cause it to become loaded).
  • For the loading state unfortunately there is no property. You have to iterate over all forms, and look whether 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.

Other Answer2

You can search the Forms collection

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

Other Answer3

If the form is in your application, you can simply track its state internally. After all-- you control the points in code when it can be created or destroyed.