May 22, 1995
A Visual Basic® application may contain many different forms. This article presents a function that can be used to determine if a form is currently loaded into memory.
Because a Visual Basic® application can contain several forms, you need to be able to determine if a form is actually loaded into memory. The function presented in the example program below tests to see if a form is loaded. This function will not load the form—it simply tests to see if it is already in memory.
This program shows how to find out if a specific form is already loaded in a running Visual Basic application.
Private Sub Form_Load()
Form2.Show
End Sub
Private Sub Command1_Click()
Dim X As Integer
X = IsFormLoaded(Form2)
If X Then
MsgBox "Form2 is loaded"
End If
X = IsFormLoaded(Form3)
If X = False Then
MsgBox "Form3 is not loaded"
End If
End Sub
Function IsFormLoaded(FormToCheck As Form) As Integer
Dim Y As Integer
For Y = 0 To Forms.Count - 1
If Forms(Y) Is FormToCheck Then
IsFormLoaded = True
Exit Function
End If
Next
IsFormLoaded = False
End Function
When you run this program, click the Command Button. A message box will pop up on the screen displaying the "Form2 is loaded" message. Click the OK command button. A second message box is immediately shown displaying the "Form3 is not loaded" message.