Re: Beginner question



> > the "dreaded" End
>
> Another thing I've not heard of. What's so bad about end?

>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: Buttons / ForeColor Property
    ... The first one is an API method of doing this and the second one is a kludge that works very nicely... ... Rick - MVP ... Prev by Date: ...
    (microsoft.public.vb.general.discussion)
  • Re: Illusion of moving LEDs
    ... > You can dump the inefficient IIf function call and use this instead ... > Rick - MVP ... Prev by Date: ...
    (microsoft.public.vb.general.discussion)
  • Re: some bit math help
    ... one-liners"; the word 'function' was used incorrectly. ... Rick - MVP ... Prev by Date: ...
    (microsoft.public.vb.general.discussion)
  • Re: Illusion of moving LEDs
    ... You can dump the inefficient IIf function call and use this instead ... Rick - MVP ... Prev by Date: ...
    (microsoft.public.vb.general.discussion)
  • Re: Saving a file to desktop with VBA
    ... Rick (MVP - Excel) ... Windows, although I don't know that for sure as I do not do any ...
    (microsoft.public.excel.programming)