What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » VB6 Question.

VB6 Question.
Author: Message:
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
42 / Male / Flag
Joined: Jan 2003
RE: VB6 Question.
About the "End": You should never use it to close a program. Instead of that, unload all the forms. When End is executed no more code is executed (except some cases I'll tell later). So if you put end, the Unload and QueryUnload events of the form won't be called and that isn't good (because is in those events where you have to put the code to free resources: free memory, close files, stops inet connections, etc....)

You have to execute "End" when there's a problem or error and your program can't handle it. Executing End is (more or less) the same as pressing the "Stop" button in VB.

When all forms are unloaded, the program may still be running (and still shown in the task manager) if there's a code like this in a button and you have pressed it before trying to close (unload) the form:

while something_that_is_true_for_long_time
   do_things
    DoEvents
wend

that code is always executing "do_things" (that may be checking if something has already happened, etc...) and also let you (because of the DoEvents) close the form (click the red X). Also, some of the IE components you're using may do something similar until you disable them in some way (I know it sounds dodgy). In the QueryUnload or in the Unload event you have to tell them to stop working.



About the "Cancel=1": When you have a form you can unload it. When you try to do that, first, the QueyUnload event is executed, then the Unload one and finally the form is unloaded. In those events you may want to ask the user if s/he really wants to close it. In case you decide not to close it, you do "Cancel=true" and the unload process is stopped. If you do it always, the only way of terminate the pregram is with the task manager (this always works).

Other scenario where you can use the "Cancel" is detect who is closing the window (form). In the QueryUnload event, you have a variable that tells you is the form is being unloaded because the result of an "Unload" intruction or because the user clicked the red X, por because Windows is going to shutdown. Read the help of that event to know more.



Sumarizing: Don't use End to terminate your program Do "Unload Me" and also do "Unload form_____" for all the opened forms. Use "End" only in case there's a fatal error that your application can't handle. If you're gonna use the "Cancel" variable, make sure you understand what it does and be sure there's a way where your code doesn't set cancel to true (or to 1, it's the same). This way, you'll be able to close the program.


:)
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
06-15-2004 08:44 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
VB6 Question. - by conless on 06-15-2004 at 02:41 AM
RE: VB6 Question. - by conless on 06-15-2004 at 02:49 AM
RE: VB6 Question. - by matty on 06-15-2004 at 03:55 AM
RE: RE: VB6 Question. - by conless on 06-15-2004 at 08:18 AM
RE: VB6 Question. - by Choli on 06-15-2004 at 08:44 AM
RE: VB6 Question. - by Millenium_edition on 06-15-2004 at 09:53 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On