Results 1 to 9 of 9

Thread: MDI Double Forms

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    45

    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

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    the most efficient way to create multiple forms is to create a Form Array..
    VB Code:
    1. Public tCount As Long 'Declare it in some module
    2. Dim ArrForm() As frmOpen 'Don't use frmOpen.show again
    3.  
    4. 'Then where you want to create another form
    5. X = X+1
    6. ReDim Preserve ArrForm(X)
    7. Set ArrForm(UBound(ArrForm)) = New frmOpen
    8. ArrForm(UBound(ArrForm)).Show

  3. #3

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    45

    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

  4. #4

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    45

    Anybody else?

    Is there anybody else who can answer these questions?

    Mat

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    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 .

  6. #6

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    45

    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

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    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 .

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Hahah...The hamster is back!!!

    VB Code:
    1. 'In a module
    2. Option Explicit
    3.  
    4. Private mcolForms    As New Collection
    5.  
    6. Public Function AddForm(ByRef MyForm As Form) As Boolean
    7. On Error Resume Next
    8.     mcolForms.Add MyForm, MyForm.hWnd & "K"
    9.     If Err.Number = 0 Then
    10.         AddForm = True
    11.     End If
    12. End Function
    13.  
    14. Public Sub RemoveForm(ByRef MyForm As Form)
    15. On Error Resume Next
    16.     mcolForms.Remove MyForm.hWnd & "K"
    17. End Sub
    18.  
    19. 'In the MDI form when you want to open another instance of frmOpen
    20. Private Sub OpenNewForm
    21. Dim frmNew As frmOpen
    22.    Set frmNew = New frmOpen
    23.    Load frmNew
    24.    If AddForm(frmNew) Then
    25.       frmNew.Show
    26.    Else
    27.       Unload frmNew
    28.       Set frmNew = Nothing
    29.    End If
    30. End Sub
    31.  
    32. 'In every childform
    33. Private Form_Unload()
    34.    RemoveForm Me
    35. 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...

  9. #9
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    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
  •  



Click Here to Expand Forum to Full Width