Stop Statement

See Also8HZ30XG              Example3TFSDW>Low

Suspends execution of the running Visual Basic code.

Syntax

Stop

Remarks

You can place Stop statements anywhere in procedures to suspend program execution.

The Stop statement suspends program execution, but unlike End, doesn't close files or clear variables.  To continue a program suspended by the Stop statement, choose Continue from the Run menu or Single Step from the Debug menu.

Under certain circumstances, you also may be able to restart program execution immediately after the Stop statement by entering a statement in the Debug window.  For example, if the Stop statement occurs in an error handler, you can enter a Resume statement in the Debug window to resume program execution.  If the Stop statement occurs in a subroutine (not a Sub procedure), you can enter a Return statement in the Debug window to continue the program.

If you don't use line numbers18F50XF or line labelsGH72Z1, you can specify which line you want to have executed next by using Set Next Statement from the Debug menu and then choosing Continue or Single Step to begin execution.  If you do use line numbers or line labels, you can continue a suspended program at a specific point by entering a GoTo statement with an appropriate line number or line label in the Debug window. 


See Also

End StatementLANEND


Stop Statement Example

For each step through this For...Next loop, Stop suspends execution.  To resume program execution, choose Continue from the Run menu.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim I                           ' Declare variable.

   For I = 1 To 10                 ' Start For...Next loop.

      Debug.Print I                ' Print I to Debug window.

      Stop                         ' Stop each time through.

   Next I

End Sub