I've been searching the internet for a solution to a particular VB problem. Came across a few somewhat heated discussions about use of the "end" statement.
The end statement terminates the execution of e.g. a form. It can be used at the click event of a button for example to close a program. It is better to use the "Unload me" rather than "end".
Thanks. That is much clearer. I always use Unload Me and then clean up in the unload event. I didn't even realize you could use End that way and thought maybe I was missing something. I guess I was, but at least I've been doing things correctly.
Many VB programmers would say: NEVER use END in your code.
They compare END statement to driving a car, and if you want to stop it, you turn the ignition off. It does not stop your car, it kills the engine off. But you are still going at 60 clicks down the highway!
Use Unload.Me, and if you clean all your stuff nicely, your code will terminate by itself. And I think this is the best way.
This is from HELP:
END statement terminates execution immediately. Never required by itself but may be placed anywhere in a procedure to end code execution, close files opened with the Open statement and to clear variables.
If you are embedding Office objects, then don't get unloaded with the END statement. If you try to run the app again, it will fail because the object is already created, and can't be created again. You should always unload objects, and then set them to nothing as soon as you are finished with them.
<The end statement terminates the execution of e.g. a form.
Just to be clear, the End statement terminates the execution of an entire application/process/exe. So, if your application is interacting with another exe/process, that process will continue to run if you don't specifically stop it. End will not call Unload and QueryUnload events, and that's why the problem that David points out occurs.
<Unload.Me
Andy, as written, that will fail to compile. As you probably already know, proper syntax is "Unload Me" without the period. Unload predates the "dot notation" syntax, and as such is termed a "Statement" rather than a "Method" by the doc. Of course, if it were a method, it would be Me.Unload anyway, since dot notation is in the form Object.Method.
I generally use End in my code when I have a fatal error, and as the last statement in my Sub Main procedure. Matter of style, I guess.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.