|
-
Aug 4th, 2002, 04:15 PM
#1
Thread Starter
Member
MDI Double Forms
I'm working with MDI forms in my current project, and have just run into a couple strange things. My problems started when I was unable to create multiple versions of the same child form, which I need to be able to do.
I looked in the MSDN help, and found that you could do this by using the set command after declaring the form as a variable.
So my program declares a form as follows:
Dim frmOpen as form
Set frmOpen = new frmOpen
frmOpen.show
(I originally tried to use a different name for the variable form, but that gave me errors)
What is strange is that this command calls two versions of the same form, one which loads and does all my planned code, and one that shows itself and sits there. I thought this might be because I was using a variable name that was the same as the name of the form, but this happened even without the same name.
Can anybody help?
Also, is there a better way to call multiple versions of the same child form?
Mat
-
Aug 4th, 2002, 04:56 PM
#2
Frenzied Member
the most efficient way to create multiple forms is to create a Form Array..
VB Code:
Public tCount As Long 'Declare it in some module
Dim ArrForm() As frmOpen 'Don't use frmOpen.show again
'Then where you want to create another form
X = X+1
ReDim Preserve ArrForm(X)
Set ArrForm(UBound(ArrForm)) = New frmOpen
ArrForm(UBound(ArrForm)).Show
-
Aug 4th, 2002, 06:14 PM
#3
Thread Starter
Member
Alright...
A Couple questions:
1) Would that entire piece of code be declared in a module? Or would just the declarations be in the module. And can you use the Dim declaration, or would it need to be public?
2) What's the purpose of the tCount declaration? SHould it be used instead of X, or does it have another purpose?
Thanks again,
Mat
-
Aug 4th, 2002, 07:50 PM
#4
Thread Starter
Member
Anybody else?
Is there anybody else who can answer these questions?
Mat
-
Aug 4th, 2002, 07:57 PM
#5
The picture isn't missing
he already said in the comments:
in a module:
Public tCount As Long 'Declare it in some module
Dim ArrForm() As frmOpen 'Don't use frmOpen.show again
wherever you want, form, module, whatever:
X = X+1
ReDim Preserve ArrForm(X)
Set ArrForm(UBound(ArrForm)) = New frmOpen
ArrForm(UBound(ArrForm)).Show
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Aug 4th, 2002, 08:29 PM
#6
Thread Starter
Member
And the variable?
Thats what I thought for that question, but I didn't want to assume that was the case (because something small that I misinterpreted might make a very large difference). Instead, I tried to get more info. My apoligies if it was an obvious answer.
But the second question was really the one that I was curious about. In that code, what does tCount do? Is it a counter for the array that should be used instead of X? Regardless, I think it is, and that seems to be working in my code, but I just want to be certain.
Thanks again for the help,
Mat
-
Aug 4th, 2002, 08:32 PM
#7
The picture isn't missing
yah he mixed up the X and the tCount. either replace tCoutn with X or X with tCount
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Aug 5th, 2002, 03:33 AM
#8
Hahah...The hamster is back!!!
VB Code:
'In a module
Option Explicit
Private mcolForms As New Collection
Public Function AddForm(ByRef MyForm As Form) As Boolean
On Error Resume Next
mcolForms.Add MyForm, MyForm.hWnd & "K"
If Err.Number = 0 Then
AddForm = True
End If
End Function
Public Sub RemoveForm(ByRef MyForm As Form)
On Error Resume Next
mcolForms.Remove MyForm.hWnd & "K"
End Sub
'In the MDI form when you want to open another instance of frmOpen
Private Sub OpenNewForm
Dim frmNew As frmOpen
Set frmNew = New frmOpen
Load frmNew
If AddForm(frmNew) Then
frmNew.Show
Else
Unload frmNew
Set frmNew = Nothing
End If
End Sub
'In every childform
Private Form_Unload()
RemoveForm Me
End Sub
That's how to keep track of what forms your MDI form has opened...You can add further functiuons to the module to add greater functionality to the collection, ie Count...
Hope this helps...
-
Aug 5th, 2002, 07:02 AM
#9
Frenzied Member
Stupid Me ..
I mixed up X and tCount...
Change the Declaration
Dim X As Long 'Instead of tCount
and the use of it is to keep track of last index on which the form has been loaded...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|