Whenever I see End in source code to exit a program, I tend not to trust the other parts of the code. Objects that are used and no longer needed should be destroyed right before their scope ends. The only thing that should remain are the in-scope objects, form controls and the form itself to take out of memory. Luckily with .NET (which I program in 100% now), the CLR takes care of this for you by garbage collecting anything that is not being referenced or is not referencing anything. You don't have to jump through hoops to take it things out of memory, because all objects are in a managed heap, and will be taken care of the CLR.
I guess the previous author must be new, because Shawn is an extemely experienced program who definitely knows the difference between Stop and End (I have never even used stop). I think the reason many people use End in their programs is that 1. that's how the book said to do it, or 2. they programmed in BASIC and the habit never died. On Sat, 5 Feb 2005 19:42:24 -0800, Shawn K. Hall <[EMAIL PROTECTED]> wrote: > > Hi "First," > > > Another writer said that "end" is not to be used. I think he > > has it confused with "Stop" > > No, I did not confuse anything. > > END is the ultimate evil in Visual Basic. Avoid it like the plague. > > > > I went back and checked help and it says just what I always > > knew -- End completely wipes the program from memory. > > Have you read Hardcore VB yet? Have you debugged memory after you've > terminated a program using END? Have you tried any "non-end" > alternatives? > > Are you willing to trust the tech writers at microsoft with the > reliability of your applications and the computers they run on? > > > > If you left any files open, it closes them. > > ONLY files that are opened via 'open' calls. And this, too, can be > fudged with End if the open call is within certain object methods of > activex controls on user forms or user classes. > > This is also in the help file, coincidentally you left it out: > > Note The End statement stops code execution abruptly, > without invoking the Unload, QueryUnload, or Terminate > event, or any other Visual Basic code. Code you have > placed in the Unload, QueryUnload, and Terminate events > of forms and class modules is not executed. Objects > created from class modules are destroyed, files opened > using the Open statement are closed, and memory used > by your program is freed. Object references held by > other programs are invalidated. > > The End statement provides a way to force your program to > halt. For normal termination of a Visual Basic program, > you should unload all forms. Your program closes as soon > as there are no other programs holding references to > objects created from your public class modules and no > code executing. > > > > Of course, Unload me will only unload the form that we're in. > > So if you have other forms still open, then they will remain > > open after the End command. > > End terminates the application and any programmatic access to those > forms. Handles are lost and the forms may close gracefully ONLY if > there are no event procedures relating to the rest of the > application that are called during queryunload, unload or terminate > events. Even then, the form will remain in memory even if it is > closed. > > > > That's the one that will close any and all forms > > that are open. After using that code, then I would > > say "End" > > The only reason to EVER use end is if you're a sloppy coder and you > do not take responsibility for the objects and references you create > within your application. Every VB program will close gracefully and > completely remove itself from memory at the end of any procedure at > which the object count is zero and there are no forms loaded. > Period. > > If your application is NOT closing gracefully, requiring you to use > END to kill it, then you're not coding correctly. There's no nice > way to put it. It's a very simple truth. > > Never Use End: > http://ReliableAnswers.com/p/?/VB/Never*Use*End > > Regards, > > Shawn K. Hall > VBHelp Moderator > http://ReliableAnswers.com/ > > > '// ======================================================= > Rules : http://ReliableAnswers.com/List/Rules.asp > Home : http://groups.yahoo.com/group/vbHelp/ > ======================================================= > Post : [email protected] > Join : [EMAIL PROTECTED] > Leave : [EMAIL PROTECTED] > '// ======================================================= > > Yahoo! Groups Links > > > > > -- --- Don Roberts - [EMAIL PROTECTED] http://www.drscripting.com http://www.freakingidiot.com '// ======================================================= Rules : http://ReliableAnswers.com/List/Rules.asp Home : http://groups.yahoo.com/group/vbHelp/ ======================================================= Post : [email protected] Join : [EMAIL PROTECTED] Leave : [EMAIL PROTECTED] '// ======================================================= Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/vbhelp/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
