Results 1 to 10 of 10

Thread: How to close a program the right way?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Belgium
    Posts
    8

    Lightbulb

    Hi,

    How do I close my VB programs the right way?
    When you use the end statement or the set ...= nothing I alsways see that the program is still in the memory.
    This is done by Ctrl+Alt+Del.

    Does somebody nows the answer.

    Thanks...

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Posts
    137

    Unload Me

    I think the proper command is: Unload Me

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Actually the best way to completely close the program is to put End in the form unload

  4. #4
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    For closing your programs try this:

    <code>
    'use this in your unload event
    Dim Form As Form
    For Each Form In Forms
    Unload Form
    Set Form = Nothing
    Next Form
    </code>
    Thanks

    Tomexx.

  5. #5
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604
    There are many different ways and every one is allowed their own opinion, i tend to use unload me because i have used end before and when i have a lot of forms is still leaves some active and the program doesn't fully close

    so i would use

    Unload me

    Merlin ?

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  6. #6
    Guest
    Set Form = Nothing - Clears up any resources a form is using.
    Unload Me - Unloads a form or control from memory.
    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.

    Code:
    Public Sub UnloadAllForms()
    Dim Frm As Form
    For Each Frm In Forms
    Unload Frm
    Set Frm = Nothing
    Next Frm
    End
    End Sub
    
    'Usage:
    Call UnloadAllForms
    I usually use all of them. End is not usually good by itself, nor is setting the form to nothing. Unload Me will work by itself well. But for less confusion and fustration, include all of them .

  7. #7
    Guest
    If you have a VB Module Prog, the proper way to end is:

    Exit Sub

    For a console program:

    FreeConsole <API>

    But if it's too many nested procedures, consider using

    End

    because ELSE it gets complicated.

  8. #8
    Guest
    Originally posted by Escaflowne
    If you have a VB Module Prog, the proper way to end is:

    Exit Sub

    For a console program:

    FreeConsole <API>

    But if it's too many nested procedures, consider using

    End

    because ELSE it gets complicated.
    If you have a VB Module Prog, the proper way to end is:

    Exit Sub
    Exit Sub - Immediately exits the Sub procedure in which it appears. Execution continues with the statement following the statement that called the Sub.

    It does not End the program. And, from VB itself:

    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.

  9. #9
    Guest
    I agree with Tomexx on this one. However, remember to name your variables properly. Change Form to something else as it is already in use by VB.

  10. #10
    Guest

    Question Just a thought

    Finished reading up on this...had a project which even when closed didn't release all resources

    = nothing.......is spot on

    But...........

    They claim the me suffix to unload shouldn't be used, rather the actual form name should be used. Any one else have an opinion on this???????

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