|
|
|
|
![]() ![]() |
Feb 10 2005, 03:25 AM
Post
#1
|
|
|
Member [Level 2] ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 81 Joined: 3-August 04 Member No.: 609 |
This tutorial applies to all those people who insist upon using "End" to close their programs:
End stops the program immediately without any thought as to what's going on - it's like a high speed train hitting a brick wall. It can cause unwanted errors and is bad programming practice in general. END gets rids of the form, but NOT its leftovers. This leaves a bunch of memory that will still be in use even after your program has supposedly closed. An object or variable won't be terminated properly - it's just not a graceful exit. The only time that it's okay to use end is in Form_Load, because there is essentially nothing to unload. Ending the program abruptly also ignores whatever code you have in your Form Terminate, Unload, or UnloadQuery subs. If you don't have leftover objects that you have neglected to nullify (ie - you are a really meticulous coder) and you don't have multiple forms loaded all at once, then "unload me" is the correct thing to do. Otherwise, putting a variation of the following in your Unload sub is the best: Code: Private Sub Form_Unload(Cancel as Integer) On Error Resume Next 'should be at the top of this sub regardless of circumstances ' If you only have 1 form: Dim o As Object For Each o In Me Set o = Nothing Unload o Next ' If you have multiple forms and you want to close the entire app: Dim f As Form For Each f In Forms Set f = Nothing Unload f next ' If you have multiple forms and possible leftovers (this is the best way, just to be safe): Dim o As Object Dim f As Form For Each f In Forms For Each o In f Set o = Nothing Unload o Next Set f = Nothing Unload f Next ' NOW you can put whatever you want, because you safely and methodically cleaned up your program's trail: Unload Me End ' you can even put end if you really really want, because at this point it's safe and there's no garbage left to clean up End Sub |
|
|
|
Mar 9 2008, 07:09 PM
Post
#2
|
|
|
Guest Feedbacks ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2,360 Joined: 21-September 07 Member No.: 50,369 |
How to close 1 form and open another in a button
[tutorial] Visual Basic 6 Can somone Please post a snippet of code on how to close a form and open one in a button. -question by Sanyo |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 15th May 2008 - 11:31 PM |