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

VB6 Question.
Author: Message:
conless
Junior Member
**

Avatar

Posts: 65
– / Male / –
Joined: Sep 2003
O.P. VB6 Question.
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 :S
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.

.zip File Attachment: ConXploreR.zip (84.91 KB)
This file has been downloaded 134 time(s).
No Image Available
06-15-2004 02:41 AM
Profile E-Mail PM Web Find Quote Report
conless
Junior Member
**

Avatar

Posts: 65
– / Male / –
Joined: Sep 2003
O.P. RE: VB6 Question.
NM all. I found I way to fix it. thx anyways.
No Image Available
06-15-2004 02:49 AM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: VB6 Question.
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
06-15-2004 03:55 AM
Profile E-Mail PM Find Quote Report
conless
Junior Member
**

Avatar

Posts: 65
– / Male / –
Joined: Sep 2003
O.P. RE: RE: VB6 Question.
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?
No Image Available
06-15-2004 08:18 AM
Profile E-Mail PM Web Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / 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
Millenium_edition
Veteran Member
*****

Avatar

Posts: 1787
Reputation: 57
Joined: Apr 2003
RE: VB6 Question.
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.
06-15-2004 09:53 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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