Results 1 to 8 of 8

Thread: How can I limit the number of child document windows in a text editor

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    West Monroe, Louisiana
    Posts
    33
    Good Morning Everyone!

    I have a text editor with an MDI. It's possible to have dozens of child windows open by repeatedly clicking "New" on the toolbar.

    How can I limit that number to two or three?

    (Code examples are always appreciated!)

    Thanks.

    Wendy

  2. #2
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    try this
    Code:
    Private Sub mnuNew_Click()
      Dim NewForm As New Form1
      Static Counter As Integer
      Counter = Counter + 1
         If Counter <= 3 Then
           Set NewForm = New Form1
           Load NewForm
         End If
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    West Monroe, Louisiana
    Posts
    33
    Thanks Wasiq!

    I made a couple of changes to fit it into my code and it works Great. Saved me a lot of time.

    Thanks again.

    Wendy

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    West Monroe, Louisiana
    Posts
    33
    OOPS! I now have a related problem.

    I need to be able to reset the counter when one or more of the child forms are closed. As it is now, once you open three files, you can't open another even if you close the first three.

    Any help is appreciated.

    Wendy


    Here'my code:

    code-------------------------------------------------------

    Private Sub mnuFileNewWorksheet_Click()
    'Purpose: Add and allow up to 3 empty child windows and new documents.

    Dim fd As New frmDoc

    Static Counter As Integer

    Counter = Counter + 1
    If Counter <= 3 Then
    Set fd = New frmDoc

    Load fd 'Load a new child window

    iDocCounter = iDocCounter + 1 'increment the child window counter
    fd.Caption = "Worksheet (" & CStr(iDocCounter) & ")"
    fd.Show 'Show the new child window
    StatusBar1.Panels(1).Text = "Worksheet Created"
    End If

    End Sub

    code-----------------------------------------------------

    [Edited by Wendy Jackson on 09-07-2000 at 02:16 PM]

  5. #5
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    try this, it should work

    add the following code to a module

    Code:
    Public Counter As Integer
    add the following to your mdi child windows unload event

    Code:
    Private Sub Form_Unload(Cancel As Integer)
    If Counter > 0 Then
        Counter = Counter - 1
    End If
    End Sub
    add the following to the menu or button which you use to open a new child window

    Code:
    Private Sub mnuOpen_Click()
    Dim NewForm As New Form1
    Counter = Counter + 1
    If Counter <= 3 Then
        Set NewForm = New Form1
        Load NewForm
    End If
    End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    West Monroe, Louisiana
    Posts
    33
    Sorry. It doesn't Work.

    Exerything works except the counter is either not being reset on unload or something else is keeping me from loading more than three forms.

    Three forms load and unload great, but after that you cannot load another form until you restart the editor.

    Any suggestions?

    Wendy

  7. #7
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Sorry! but there was a little mistake. The 'counter=counter+1' line needed to be enclosed in the if clause. Its working fine now. try it.

    add the following code to a module

    Code:
    Public Counter As Integer
    add the following to your mdi child windows unload event

    Code:
    Private Sub Form_Unload(Cancel As Integer)
    If Counter > 0 Then
        Counter = Counter - 1
    End If
    End Sub
    add the following to the menu or button which you use to open a new child window

    Code:
    Private Sub mnuNew_Click()
    Dim NewForm As New Form1
    If Counter < 3 Then
        Counter = Counter + 1
        Set NewForm = New Form1
        Load NewForm
    End If
    End Sub

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    West Monroe, Louisiana
    Posts
    33
    Thanks again, Wasiq!

    I had just found the problem and was testing it when your post came. It seems to be working great!

    Thanks a bunch!

    Wendy

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