Using Stop Statements

Placing a Stop statement in a procedure is an alternative to setting a breakpoint. Whenever Visual Basic encounters a Stop statement, it halts execution and switches to break mode. Although Stop statements act like breakpoints, they aren't set or cleared the same way.

Caution   Be sure to remove any Stop statements before you create an .exe file. If a stand-alone Visual Basic application (.exe) encounters a Stop statement, it treats it as an End statement and terminates execution immediately, without any QueryUnload or Unload events occurring.

Note   It's usually better to use the Assert method rather than a Stop statement. The Assert method halts execution only when a specified condition isn't met; unlike the Stop statement, calls to the Assert method are automatically removed when the application is compiled. For more information, see "Verifying Your Code with Assertions" later in this chapter.

Remember that a Stop statement does nothing more than temporarily halt execution, while an End statement halts execution, resets variables, and returns to design time. You can always choose Continue from the Run menu to continue running the application.

For More Information   See "Stop Statement." And see "How to Handle Errors" earlier in this chapter for an example that uses the Stop statement.