Stop Statement

Syntax

Stop

Description

Halts program execution.

Rules at a Glance

  • There is no limit to the number and position of Stop statements within procedures.

  • The Stop statement acts like a breakpoint, placing the program in break mode and highlighting the current line in the development environment, allowing you to step through the code line by line.

Programming Tips and Gotchas

  • Stop is intended primarily for use in the design-time environment, where it suspends program execution without terminating it. In the runtime environment, however, Stop displays a message box that reads Stop statement encountered before terminating program execution. Needless to say, users are sure to find this type of behavior baffling. Consequently, all Stop statements should be removed (or commented out) before compiling the executable file.

  • Care must be taken when using the Stop statement, because unlike the End statement, Stop doesn't explicitly close any open files or clear variables unless running in a compiled EXE.

  • These limitations suggest that the Stop statement, which exists primarily to permit a programmatically generated breakpoint, is best replaced by explicit breakpoints in the design-time environment.

See Also

End Statement

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.