|
-
Sep 7th, 2000, 10:38 AM
#1
Thread Starter
Member
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
-
Sep 7th, 2000, 12:10 PM
#2
Hyperactive Member
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
-
Sep 7th, 2000, 12:55 PM
#3
Thread Starter
Member
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
-
Sep 7th, 2000, 01:12 PM
#4
Thread Starter
Member
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]
-
Sep 7th, 2000, 01:33 PM
#5
Hyperactive Member
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
-
Sep 7th, 2000, 02:40 PM
#6
Thread Starter
Member
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
-
Sep 7th, 2000, 10:46 PM
#7
Hyperactive Member
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
-
Sep 7th, 2000, 10:56 PM
#8
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|