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.
End statement stops code execution abruptly, and does not invoke the
Finalize method, or any other Visual Basic code. Object references held by other programs are invalidated. If an
End statement is encountered within a
Catch block, control does not pass to the corresponding
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.
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
You should use
End sparingly, and only when you need to stop immediately. The normal ways to terminate a procedure (Return Statement and Exit Statement) 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
When followed by an additional keyword, End <keyword> Statement delineates the end of the definition of the appropriate procedure or block. For example,
End Function terminates the definition of a
The following example uses the
End statement to terminate code execution if the user requests it.
Sub Form_Load() Dim answer As MsgBoxResult answer = MsgBox("Do you want to quit now?", MsgBoxStyle.YesNo) If answer = MsgBoxResult.Yes Then MsgBox("Terminating program") End End If End Sub
Smart Device Developer Notes
This statement is not supported.