CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2004
    Posts
    75

    Loading MDI child frm and memory problem

    Hello,
    How many times a MDI child form can be loaded and shown? Does it depend on the available memory of the computer? If so, how can I check out if there´s enough memory to load the form correctly?
    I ask this because I´m having a weird problem: I have a MDI parent with a menu bar from where I choose some option which causes a MDI child form to open with frmX.load. (The frmX.show is in the form_load procedure).
    The form has a SSTAB and several controls in it. If I repeat the operation (choose the same option from the menu), new instances of the same form are loaded but suddently I get a VB6 error message (no number available) or the screen just goes black and the computer halts needing to restart it!
    I´m suspecting it is a memory problem. I have a pentium3, Windows ME and 128 of RAM that I have recently upgraded to 384 because I had memory problems running VB6. Are my resources still too low? Is the MDI loading problem related to the memory? Should I avoid loading new instances of the form from code?
    What are the ideal computer resources to develop (and run) a VB6 medium size application that also uses ADO to manipulate access databases?
    I appreciate any help.
    Sandra

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362
    Just a thought, but is the original form frmX(0) in a control array? To load new forms like that, I belive it should be.


  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    >The form has a SSTAB and several controls in it

    Hope you have arrays of controls...
    In any case, it could be limit is around 255 forms (and 255 controls on it), but you
    should not reach that limit, and in any case you should experience a slowing
    down of everything, before.
    How many new instances can you load before matter pops up?
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jun 2004
    Posts
    75
    Ups! I´m very close to the limit!
    The form (is not an array of forms), it contains a SSTAB with 5 tabs, and the controls spread in the tabs are most of them arrays of controls (labels, textboxes and combo boxes) plus some frames... but I´ve counted them and they are 225!! (that is a total, I mean, counting each element of the arrays)
    I reproduced the fault in order to count the number of instances that can be opened and this time I was able to see an "out of memory error", and the computer dies. It allowed me to open 4 instances only (either running the application from VB6 or from a .exe with VB6 closed -same behavior-)
    I´m a lot worried because the form does not contain any data yet, it is supposed to show data from a database using ADO, and plus, it will show a map (graphics). Then I wonder how much memory this will need in order to behave correctly.
    Do you consider that restricting the form to show just one time (1 instance) will be enough or should I also redesign the form to split it in other "sub-forms" (perhaps pop up forms called from a main form)?
    Do you know of any method to check the amount of memory that a form consumes and that is available in the system in order to load it without crashing the system? (That is a mayor fault!)
    Thank you very much for your help.
    Sandra
    Last edited by txmslbg; July 28th, 2004 at 11:13 AM.

  5. #5
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    I think you're going to have to take a long hard look at how you are using and releasing memory. It is obviously a big factor with the way your have programmed your application - you should consider whether or not you really have to have all those controls on the form - and when you release the memory.

    You may have to redesign your application unfortunately - or make the minimum spec of your machine (and those you will be installing it on) up to whatever is actually required to run your program after you've tweaked the memory usage.

    I had a similar problem a couple of years ago, where I ended up with 230 controls on a form (with SSTabStrip, 5 tabs). I solved it by creating the controls dynamically depending on which radio button was selected on a particular tab - a bit messy but it ended up being what the users wanted.

    Good luck with it all!!!!!
    Be nice to Harley riders...

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    You might also consider a bit of re-design:
    ie: could you use a flexgrid and a single textbox and combobox instead of a lot of textboxes and labels?
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Jun 2004
    Posts
    75
    Thanks for your ideas.
    I will do both: Create controls dynamically and re-design the form.
    Plus I will restrict it to show only once.
    Big challenge has been this fist VB project for me!

    Regards,
    Sandra

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Use only one instance:
    dim FrmX as Form1
    set FrmX=Form1
    ...
    FrmX.Show
    ....
    = no "new" operator
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Limit of arrays of controls

    With arrays of controls you can have more than 255 controls
    ie:
    'need a textbox withindex 0 named TxtCtrl
    'a commandbutton named CmdTest
    Code:
    Option Explicit
    'in my pc limt was (in ide) : 9836 elements of TextBox ...
    Private Sub CmdTest_Click()
    Dim Counter As Long
    With TxtCtrl(0)
        If Not IsNumeric(.Text) Then
            MsgBox "need a number!"
            .SelStart = 0
            .SelLength = Len(.Text)
            .SetFocus
            Exit Sub
        ElseIf CLng(.Text) < 0 Then
            MsgBox "must be a positive number!"
            Exit Sub
        Else
            .Text = CLng(.Text) 'make it a non floating one ;-)
        End If
        
    End With
    Screen.MousePointer = vbHourglass
        'if you already stepped here, remove
        'the extra txtboxes
        If TxtCtrl.UBound > 0 Then
            For Counter = TxtCtrl.UBound To 1 Step -1
                Unload TxtCtrl(Counter)
            Next
        End If
        
        'create as many as requested
        For Counter = 1 To TxtCtrl(0).Text
            Load TxtCtrl(Counter)
        Next
    Screen.MousePointer = vbDefault
    
    MsgBox "Done! I loaded " & TxtCtrl.UBound & " textboxes"
    
    End Sub
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  10. #10
    Join Date
    Jun 2004
    Posts
    75
    That is a great way to check out the number of textboxes. I will try it out and see how many I get.
    And also, I have just left the frmX.show as you suggested before.
    My customer still wants to be able to open at least to instances of the form. I will make a deep analysis of what he wants and think of ways to satisfy his demand.
    Your help has been really valuable.
    Thank you very much.
    Sandra

  11. #11
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Quote Originally Posted by txmslbg
    Thank you very much.
    Sandra
    You're welcome
    (btw, Italian?)
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured