Results 1 to 18 of 18

Thread: Unload help please

  1. #1
    Guest

    Red face

    Hi all:
    i try to exit my program, how can i unload all my forms? i am using a MDI form and few child form, how can we count the number of the child forms i got? i use different name for each form, i can not use forms.count.... any other way?

  2. #2
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    To Unload your forms place this code in the Form_Unload event of your MDI Form.
    Code:
    Dim Frm As Form 
    
    For Each Frm In Forms 
    Unload Frm 
    Set Frm = Nothing 
    Next Frm 
    End
    Dr_Evil
    Senior Programmer
    VS6 EE
    VS.NET EA

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'declares are not needed
    Code:
    'unload all forms
      For Each Form In Forms
        Unload Form
        Set Form = Nothing
      Next
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Guest

    Thanks

    Do you think the codes that you gave me can work if the froms are having different name? like aform, bform? and do you know what is Me.load? and how can we know wich form is visible if we want to hide it?
    and do we need the END and why

  5. #5
    Guest
    Q1: Do you think the codes that you gave me can work if the froms are having different name?

    Code:
    Public Sub UnloadAllForms()
    Dim frm As Form
    For Each frm In Forms
    Unload frm
    Set frm = Nothing
    Next frm
    End
    End Sub
    
    Usage
    
    UnloadAllForms
    The codes given will unload all forms no matter what the name is.

    Q2: and do you know what is Me.load?

    Code:
    Load form1
    This will process code that is in the Form_Load event.

    Q3: and how can we know wich form is visible if we want to hide it?

    Code:
    Public Sub VisibleForms()
    Dim frm As Form
    For Each frm In Forms
    If frm.Visible = True Then
    Debug.Print frm.Name & ".Visible = " & frm.Visible
    Else
    End If
    Next frm
    End Sub
    This will print whatever form is visible on the debug window. If it's not visible, it will not print anything.

    Q4: and do we need the END and why

    END - Terminates execution. Never required by itself but may be placed anywhere in a procedure to close files opened with the Open statement and to clear variables.

    You don't need END, it is not required, but you may use it if you wish. Just don't use it by itself, as stated above.

  6. #6
    Guest

    thanks

    Thanks, I appreciate your help

  7. #7
    Guest

    Red face Another question

    Also, By any chance if you know how can we load all the forms together at the beginning of playing splashform... because i am not sure if we load them together or we load them when we say show at teh first time... also, how can we know the time to load the forms together at the first time , as we need to let the splash form to stay until we finish loading all the child form.. thanks again

  8. #8
    Guest

    Re: <?>

    Originally posted by HeSaidJoe
    'declares are not needed
    Sure they're not needed but it's a good programming habit to declare them because in many languages (such as C++), it will not compile unless you declare your variables.

  9. #9
    Guest

    Red face ???

    What do you mean? Are you answering my question?

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'unload all forms
      For Each Form In Forms
        Unload Form
        Set Form = Nothing
      Next
    Megatron:

    Why would I have to declare anything as form when
    I am unloading each form in forms.

    I really can't understand why I have to do this

    Declare Frm as Form
    For Each Frm In Forms

    If you use a single form you don't say
    Dim frm as frm
    Unload frm

    You simply say
    Unload Form1
    or
    Unload Me

    There is no declare so why should you declare
    a var as a form just to unload multilple forms?
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  11. #11
    Guest

    Talking

    HeSaidJoe, thanks for the help that you gave, so if i have lots of MDI child form and some other forms, when i unload, i don't need to declare right....
    Also, do you have any clue about the splash form that i asked above?
    Thanks again...

  12. #12
    Guest

    Re: Another question

    Originally posted by dragonyian
    Also, By any chance if you know how can we load all the forms together at the beginning of playing splashform... because i am not sure if we load them together or we load them when we say show at teh first time... also, how can we know the time to load the forms together at the first time , as we need to let the splash form to stay until we finish loading all the child form.. thanks again
    Code:
    Private Sub Form_Load() 'splash screen
    Load form1
    Load form2
    Load form3
    DoEvents 'load all forms
    'after all are loaded...show them all
    Form1.Show
    Form2.Show
    Form3.Show
    'etc.
    'etc.
    End Sub

  13. #13
    Guest

    Talking Second Question / Splash Form / Form Load

    Maybe i should make myself clear... or maybe i should have explained this clearer....
    I have a MDI form with 10 child forms and 2 independent forms and
    when i started the project, i have a form called splash form,(project property) what it does just like its name... show a picture... i never use form load in my whole program.. i just "show" them, i am not sure if it is the correct way to do that... if i need to load them, where should i put the load code, load form1, load form2..... if i do like you said put them under splash form, then will the program goes faster than only "show-used" program? how can we know how long to load all the forms together... because i need to show the picture on the splash form also, if it goes too fast.. maybe the user might not be able to see the picture at all.... but it is how others do, i know... so, what would be your suggestion
    thanks

  14. #14
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    I could be wrong on this but I do belive all forms are loaded when your application is loaded and the only form to show it the form declared as your startup form.

    You can use VbShow and VbHide to show and not show your forms as long as you don't unload any within the running of your app. They should all be unloaded and set to nothing when you unload your application.
    If you have 10 to 15 forms they should load quickly and I would assume that if you let your splash screen show for 4 to 8 seconds you should have no problems.

    Code:
    frmSplash.hide
    form1.show
    form2.show
    form3.show
    form4.show

    Whatever...

    example: if you have 4 forms and you want only #2 shown

    form1.hide
    form3.hide
    form4.hide
    form2.show

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  15. #15
    Guest
    Correct me if i am wrong,because i am new to programming
    if all the child forms are loaded automatic, why we still need the load function/event?

  16. #16
    Guest
    Say, you used this on a secondary form to free up memory like:

    Code:
    unload uselessform
    and later you want to show it again, you would use:

    Code:
    load uselessform
    HeSaidJoe: Yes, all forms ARE loaded at startup so if you call the form.show method, it never returns an error.

    Load is the same as:

    Code:
    Dim Form1 As New Form1
    <except it can't be used to create new instances or forms.> new instance of form = new form

    get it?


  17. #17
    Guest

    Talking

    So, in that case, how can we load those we need when we need it.. because as you said... it will load everything when we run the program... what would be the best hit, tip to handle load/unload MDI child form....

  18. #18
    Guest
    Code:
    Unload MDIForm.ActiveForm
    And

    Code:
    Set ff as New Form1
    ff.Show
    Also, I'll give you the code for Unloading ANY form soon.

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