|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Terminates execution immediately.
You can place the End statement anywhere in a procedure to force the entire application to stop running. End closes any files opened with an Open statement and clears all the application's variables. The application closes as soon as there are no other programs holding references to its objects and none of its code is running.
The End statement stops code execution abruptly, without invoking the Dispose or Finalize method, or any other Visual Basic code. Object references held by other programs are invalidated. If an End statement is encountered within a Try or Catch block, control does not pass to the corresponding Finally block.
The Stop statement suspends execution, but unlike End, it does not close any files or clear any variables, unless it is encountered in a compiled executable (.exe) file.
Because End terminates your application without attending to any resources that might be open, you should try to close down cleanly before using it. For example, if your application has any forms open, you should close them before control reaches the End statement.
You should use End sparingly, and only when you need to stop immediately. The normal ways to terminate a procedure (and ) not only close down the procedure cleanly but also give the calling code the opportunity to close down cleanly. A console application, for example, can simply Return from the Main procedure.
The End statement calls themethod of the class in the namespace. Exit requires that you have permission. If you do not, a error occurs.
When followed by an additional keyword,delineates the end of the definition of the appropriate procedure or block. For example, End Function terminates the definition of a Function procedure.