Re: Check if a form is loaded
- From: "Ken Halter" <Ken_Halter@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 13 Sep 2005 08:35:10 -0700
"Bent Lund" <bstlu@xxxxxxxxx> wrote in message
news:%23IKVhaHuFHA.1244@xxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> yes but is there a Forms collection in VB6?
>
> Do I need to add a library of some sort?
>
> Bent
Yes... you can type Forms into a code window, select it and hit F1 to see
help on the "Form Object, Forms Collection"
Here's 3 ways to check for loaded forms. There are many more. It all depends
on what you want to do with the result.
'============
Option Explicit
Private Sub Form_Load()
'Project has forms named "Form1" and "Form2"
MsgBox IsFormLoaded("Form2") 'False
Load Form2
MsgBox IsFormLoaded("Form2") 'True
Unload Form2
MsgBox IsFormLoaded("Form2") 'False
Dim f As Form
Set f = LoadedForm("Form2")
If f Is Nothing Then
Debug.Print "Form2's not loaded"
Else
f.Show
End If
Load Form2
Set f = LoadedForm("Form2")
If f Is Nothing Then
Debug.Print "Form2's not loaded"
Else
f.Show
End If
End Sub
Private Function IsFormLoaded(FormName As String) As Boolean
'Returns True if form name is found
Dim f As Form
For Each f In Forms
If f.Name = FormName Then
IsFormLoaded = True
Exit For
End If
Next f
End Function
Private Function FormsCount(FormName As String) As Long
'Returns the number of forms named FormName - good for MDI Child forms,
etc
Dim f As Form
For Each f In Forms
If f.Name = Name Then
FormsCount = FormsCount + 1
End If
Next
End Function
Private Function LoadedForm(FormName As String) As Form
'Returns reference to form if form name is found
Dim f As Form
For Each f In Forms
If f.Name = FormName Then
Set LoadedForm = f
Exit For
End If
Next f
End Function
'============
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
.
- References:
- Re: Check if a form is loaded
- From: Bob Butler
- Re: Check if a form is loaded
- From: Bent Lund
- Re: Check if a form is loaded
- Prev by Date: Re: Source of EXE Size OT
- Next by Date: Re: Source of EXE Size
- Previous by thread: Re: Check if a form is loaded
- Next by thread: Re: Check if a form is loaded
- Index(es):
Relevant Pages
|