VB6 Question. - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: VB6 Question. (/showthread.php?tid=27223)
VB6 Question. by conless on 06-15-2004 at 02:41 AM
Ok, as some know that I am creating a webbrowser. I coded all of it but since I am using IE components I guess its not all mines
anyways, I am almost done with it, but I have this problem.
Whenever I am using my ConXploreR I am trying to close it by hitting the X on the top right, you know the one next to the minimize and maximize buttons. well it closes and all. but it is still running in the taskmanager. its still there.
maybe is one of these problems..
in File|close I added this code 'to close the program
quote: 'terminate the program
unload form1
End
Should I only add End?
is that the problem that is not closing right?
iono. let me know plz.
thx
check it out for your self.
RE: VB6 Question. by conless on 06-15-2004 at 02:49 AM
NM all. I found I way to fix it. thx anyways.
RE: VB6 Question. by matty on 06-15-2004 at 03:55 AM
quote: Originally posted by conless
NM all. I found I way to fix it. thx anyways.
Although you found away of doing it heres some other things.
code: Private Sub Form_Unload(Cancel as Integer)
End 'Closes program from Memory
End Sub
Private Sub Form_Unload(Cancel as Integer)
Cancel = 1 'Doesn't allow user to close application
End Sub
RE: RE: VB6 Question. by conless on 06-15-2004 at 08:18 AM
quote:
code: Private Sub Form_Unload(Cancel as Integer)
Cancel = 1 'Doesn't allow user to close application
End Sub
You wont be able to close not even from the taskmanager?
RE: VB6 Question. by Choli on 06-15-2004 at 08:44 AM
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.
RE: VB6 Question. by Millenium_edition on 06-15-2004 at 09:53 AM
End is a great way to stop your program, at least the doevents loop will be stopped. It's useful if you want to add an option to terminate your program straight away.
|