Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI Child Forms

Status
Not open for further replies.

psandekian

Programmer
Oct 12, 2000
48
US
Hi. I'm working on a MDI form and I limit the number of child windows open at one time to 8. My child windows are all the same yet they have different property values. My question is if the user opens 2 child windows and then closes the first child window, how can I refer to this 2nd window as the first? For instance, I set my child forms

Code:
dim frm() as frmGraph   'my child form

When I use this method and the first child window is closed and the second remains, the rest of my code starts a new form. I need to be able to shift things down. So if I have 5 windows open and 3 are closed (in any order), the remaining 2 I need to be frm(0) and frm(1). Is this possible? If so, how?

Thanks.
Patty [sig][/sig]
 
Patty,

Probably a stupid question but why do you need to re-number them?

[sig][/sig]
 
This procedure assumes that frm() and temp() are both arrays of the same type and size. Simply add a declaration for an array temp() As frmgraph. If you are resizing frm() throughout your program make sure you resize temp() in all the same places. It also assumes that when you unload a child form you set its place in the array to nothing, like this: Set frm(ClosedChild) = Nothing


Private Sub ManageChildWindows()
Dim Count As Integer
Dim CurPosition As Integer

CurPosition = 0

For Count = 0 To UBound(frm) - 1
If frm(Count) <> Nothing Then
Set temp(CurPosition) = frm(Count)
CurPosition = CurPosition + 1
End If
Next Count

Set frm() = temp()

End Sub

I havent tried this out, and ive never worked with mdi before but i think it will work like you want. Give it a try and let me know if you have any problems.

Good Luck [sig]<p>Ruairi<br><a href=mailto:ruairi@logsoftware.com>ruairi@logsoftware.com</a><br>Experienced with: <br>
VB6, SQL Server, QBASIC, C(unix), MS Office VBA solutions<br>
ALSO: Machine Control/Automation using GE and Omron PLC's and HMI(human machine interface) for industrial applications[/sig]
 
I tried it and it didn't like:

Code:
If frm(Count) <> Nothing Then

It says &quot;Compile Error: Invalid use of object.&quot; and it has &quot;Nothing&quot; highlighted.

Do you have any suggestions? I like this approach so I'll keep working it. If I figure it out, I'll post it.

Thanks for your advice!
Patty


[sig][/sig]
 
frm(Count) <> Nothing needs to be replaced with:

Not frm(Count) is Nothing

Also, as just one more of the infinite ways of doing this, have you tried saving the forms in a Collection object? If you remove an item from a Collection, all the subsequent items are automatically moved down in the index order. Thus, deleting item 3 will cause (what was once) item 4 to become item 3, item 5 to become item 4, etc. This may solve your problem without any code necessary.

Steve [sig][/sig]
 
Steve,

Thanks. That got me closer. But the if not statement doesn't recognize that I set the frm(0) = to nothing.
It also says Type Mismatch for frm = temp yet they are the same datatype of frmGraph.

Here's my timer code on my MDIform:

Code:
Private Sub tmrRefresh_Timer()    

    CurPosition = 0
    
'rename if bUnload = true
    If bUnload = True Then
        For count = 0 To UBound(frm) - 1
            If Not frm(count) Is Nothing Then
                Set temp(CurPosition) = frm(count)
                CurPosition = CurPosition + 1
            End If
        Next count
        frm = temp
        For iLoop = 0 To m_iCount - 1
'            If modFFT.bFormNumber(iLoop) Then
                frm(iLoop).Caption = &quot;Graph - &quot; & CStr(iLoop + 1)
'            End If
        Next iLoop
        bUnload = False
    End If

'For each graph
    For iLoop = 0 To m_iGraphCount - 1
' a lot of code follows to set up each graph as frm(iloop)
    next iLoop
end sub

And my code for Unload form for frmGraph:

Code:
Private Sub Form_Unload(Cancel As Integer)
    
    'turn timer off temporarily
    MDIForm1.tmrRefresh.Enabled = False
    
    Set frmGraph = Nothing

    'variable to rename graphs
    MDIForm1.bUnload = True
    
    'turn timer back on
    MDIForm1.tmrRefresh.Enabled = True
    
End Sub

I would use Collections but I have not worked with them and I think I'm almost there with this code.

Thanks!
Patty

[sig][/sig]
 
Patty,

Your frm = temp line is causing an error because you need to use the set statement.

As Ruairi stated above, the correct syntax is : set frm() = temp().

I don't work with arrays very much, so I'm not sure if you need the elipses after the variable names. If the syntax above does not work, try set frm = temp.

Steve [sig][/sig]
 
Steve,

I was able to get the type mismatch corrected. Here's the code:
Code:
        For count = 0 To UBound(frm) - 1
            Set frm(count) = temp(count)
        Next count
It didn't like set frm() = temp().

Anyway, do you have any ideas about the unload form not setting the active graph of frm() = nothing? If I can get this, then I think it will work.

Thanks!
Patty [sig][/sig]
 
Try this:

In your frmGraph code, insert the following code:

Private iFormIndex as Integer
...
Public Property Get Index() as Integer
Index = iFormIndex
End Property

Public Property Let Index(NewIndex as Integer)
iFormIndex = NewIndex
End Property

...

Private Sub Form_Unload(Cancel As Integer)

'turn timer off temporarily
MDIForm1.tmrRefresh.Enabled = False

'Set frmGraph = Nothing -- replace this line with the
'one below
Set frm(iFormIndex) = Nothing

'variable to rename graphs
MDIForm1.bUnload = True

'turn timer back on
MDIForm1.tmrRefresh.Enabled = True

End Sub

Whenever you create a new frmGraph, you will need some code resembling the following:

Sub CreateGraph()

Dim NewIndex as Integer
Dim frmNewGraph as frmGraph

NewIndex = UBound(frm) + 1

Set frmNewGraph = New frmGraph
frmNewGraph.Index = NewIndex

ReDim Preserve frm(NewIndex)
Set frm(NewIndex) = frmNewGraph


End Sub

As I stated before, I don't work with arrays much (I prefer collections), so this code may not be precise. The point is that you will set the Index property of the new form to the next number in the array.

Then, in your timer refresh, after the line

Set temp(CurPosition) = frm(count),

have the line

temp(CurPosition).Index = CurPosition

In this way you are always tracking where in the array each form is, so you can set the proper array element to nothing when you unload the form.

Hopefully, this will solve the problem.

Steve [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top