Results 1 to 16 of 16

Thread: END VS UNLOAD

  1. #1

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Talking

    What is the defference between END and Unload form1. I here so many complaints about which one to do but never a good resaonable explanation about which one is better to use. So one day a long time ago I heard someone tell me to use unload and another to end so what I did was put this code in the module.

    Code:
    Sub killapp()
    unload form1
    unload form2
    unload form3
    unload form4
    end
    end sub
    Is that better then using them both singaly or what should everyone be using?

    Thanks!!
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  2. #2
    Guest
    I like this better:

    Code:
    Private Sub Form_Unload(Cancel As Integer)
        Dim Form As Form
        For Each Form In Forms
            Unload Form
        Next Form
    End Sub
    then you just go

    Code:
    Unload Me
    and your whole program will end.

  3. #3

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408
    But why use Unload over end? I don't understand why unload is said to be better then End.
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    End is to end the entire project. When you use END, it automatically unload all forms along with it.

    Unload is to unload ONE form and not all forms. Of course, if you unload all forms, the last one will END your program.
    Chemically Formulated As:
    Dr. Nitro

  5. #5
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    Using the end doesn't free up all the memory that your program uses. After you unload your forms it is also a good idea to 'Set form = nothing'.

    This is just a memory thing. You need to clear it up once the program is done.

  6. #6
    Guest
    Actually, End differs from Unload and I recommend against using it simply because when you use End instead of Unload, none of the unload events (QueryUnload, Unload, Terminate) are triggered whereas Unload will trigger all of them.

  7. #7
    Guest
    and Unload triggers the unload event of the form. if you use end it doesnt, this can be a problem when your subclassing and have the unsubclass sub called in the unload event.

  8. #8

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Talking

    Ok what happens if you use both end and unload. Will it free up the memory and work all perfect like.

    Code example from Denniswrenn but modified
    Code:
    Private Sub Form_Unload(Cancel As Integer)
        Dim Form As Form
        For Each Form In Forms
            Unload Form
        Next Form
        End
    End Sub
    Is that the correct and proper way to do it?
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  9. #9
    Guest
    That won't make very much difference.... Because it will end even if you have 50 forms open with my original code...

  10. #10

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Thumbs up

    Ok thanks. That clears everything up for me. And thank you gain everyone!!!
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  11. #11
    Guest
    Think of it this way. Using End is like hitting the stop button on VB and using Unload is like clicking the X on your app.

  12. #12
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    My 2 cents...

    Always unload your forms. If you do this, using the End statement is not required.

    I created an app or two before being aware of the importance of unloading forms, using only the End statement to stop the program. Although my app was terminated, it would still be visible as a running program when I pressed CTL-ALT-DEL. When I started unloading my forms to end my apps, this problem went away.

    I just wanted to point this out because I didn't see it mentioned in the previous posts and this is a visible way to see a difference between the two methods.

    All the best.

  13. #13
    Guest
    You should also set your forms to nothing to free up resources, as thedee23 said. So, adding a bit to Dennis's code:

    Code:
    Public Sub UnloadAllForms()
    Dim Frm As Form
    For Each Frm In Forms
    Unload Frm
    Set Frm = Nothing
    Next Frm
    End
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    UnloadAllForms
    End Sub
    And overall, I'd use both the Unload and End statements.

  14. #14
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113
    So are you basically saying (GURU) that we should avoid using End where possible. I Unload every form after a new form is required. Then when someone clicks exit from any form I just use END. Does this mean that my resources arent being freed. Would the Process viewer in Visual Studio Tools show resources being hogged up due to forms that werent unloaded?

    BTW...how do u put the VB code into this thing?




    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  15. #15
    Guest

    Exclamation

    Just a quick warning about the 'End' statement.
    My company had an application with a rogue 'End' in it. When you use the VBSQL control to access MS SQL Server, you can get into all sort of trouble if you do not close down your connections in the correct order (it will GPF on app exit).

    I have seen this with other controls as well, so you are best not using 'End' until you have manually unloaded your whole app. In fact as everyone else has said, just don't use 'End' your app should be keeping track of what is unloaded and not.

    We only use the 'End' statement in one situation, when the app has realised that all hell has broken loose and it should quit as fast as possible.

    Everyone else seems to have covered this, but just thought I'd post what can go wrong using 'End'.

  16. #16
    Guest
    I've tried unloading all forms, but I'm still hanging up when I exit my app. My app has a number of forms that allow the user to go 'back' or 'next'. I show a form, then hide the current form when they click on 'back' or 'next'. After the current form is hidden I show the new form and keep doing this until all forms have been displayed and 'next' is clicked one last time. My app runs fine if the user never clicks 'back'.

    Thanks in advance for your replies.

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