Re: Exit from application

From: Rick Rothstein (rickNOSPAMnews_at_NOSPAMcomcast.net)
Date: 01/04/05


Date: Tue, 4 Jan 2005 08:37:57 -0500


> I have a stupid (maybe) problem when I want to exit from my app.
> isn't a big application. it's a small application where I use winsock
and
> ADO.
> so the aplication is lanched from another application and after it
finish
> his work
> it must end.
>
> all it's ok till arrive at the vb END Commad
> and here all freeze. When I run as exe it freeze and when I run in
debug
> mode from VB IDE
> freeze too.
>
> cand somebody tell me what it's the problem?

>From an old post of mine...

Never, never, never, never, ever use the End statement to terminate your
program.

End should ***NEVER*** be used in VB. When you start writing more
complex code, you will find that in certain situations, VB needs to do
some cleaning up (and you need to help it). You can go to this Google
newsgroup link

http://groups.google.co.uk/advanced_group_search?num=100&as_scoring=d&as_ugroup=*.vb*

and look up the exact word "vb" and the exact phrase "end statement"
(leave off the quotes in both of these) to find the many ways people
have explained the why and what of not using the End statement. Suffice
it to say that the End statement stops your program in the same way
running into a brick wall stops your car... immediately. You don't get a
chance to coast to a stop and turn your key to the off position, open
the door and exit the vehicle. The same thing happens with the End
statement... BOOM!, everything stops dead in its tracks right then and
there and the program ends. The moral is... NEVER, NEVER, NEVER use the
End statement in your program! (And, in the same way, using that "solid
square" icon on VB's Toolbar, or clicking End in the Run menu, to stop
your project during development is the identical equivalent of executing
an End statement in code... you shouldn't do that either.)

Consider this... From the VB Help Files: "More About Forms"

"The End statement ends an application immediately: no code after the
End statement is executed, and no further events occur. In particular,
Visual Basic will not execute the QueryUnload, Unload or Terminate event
procedures for any forms. Object references will be freed, but if you
have defined your own classes, Visual Basic will not execute the
Terminate events of objects created from your classes."

In addition to the End statement, the Stop statement halts an
application. However, you should use the Stop statement only while
debugging, because it does not free references to objects.

Rick - MVP



Relevant Pages

  • Re: Form wont show up for the first time
    ... End statement stops your program in the same way running into a brick wall ... Basic will not execute the QueryUnload, Unload or Terminate event procedures ... Object references will be freed, but if you have defined your ...
    (microsoft.public.vb.general.discussion)
  • Re: UserControl Terrors
    ... > stop button,) the VB IDE crashes and shut down entirely. ... running into a brick wall stops your car... ... Visual Basic will not execute the QueryUnload, Unload or Terminate event ...
    (microsoft.public.vb.general.discussion)
  • Re: Error Message VB6
    ... End statement stops your program in the same way running into a brick wall ... Basic will not execute the QueryUnload, Unload or Terminate event procedures ... Object references will be freed, but if you have defined your ...
    (microsoft.public.vb.general.discussion)
  • Re: Error Message VB6
    ... End statement stops your program in the same way running into a brick wall ... Basic will not execute the QueryUnload, Unload or Terminate event procedures ... Object references will be freed, but if you have defined your ...
    (microsoft.public.vb.general.discussion)
  • Re: Error Message VB6
    ... End statement stops your program in the same way running into a brick wall ... Basic will not execute the QueryUnload, Unload or Terminate event procedures ...
    (microsoft.public.vb.general.discussion)