Stepping Over a Procedure

Suppose that the current statement in MyProcedure calls the SpecialMsg procedure. If you choose Debug | Step Over (Shift+F8) instead of Debug | Step Into (F8), Visual Basic will quickly execute all the statements inside the SpecialMsg procedure and select the next statement in the calling procedure, MyProcedure. All during the execution of the SpecialMsg procedure, Visual Basic continues to display the current procedure in the Code window.

© Hands-On 9-5: Stepping Over a Procedure

This hands-on refers to the Access form named frmTimeSheet that you created in Custom Project 9-1 at the beginning of this chapter.

1. Enter the MyProcedure and SpecialMsg procedures in a new module.

Sub MyProcedure()

Dim myName As String myName = Forms!frmTimeSheet.Controls(1).Name

' choose Step Over to avoid stepping through the ' lines of code in the called procedure - SpecialMsg SpecialMsg myName End Sub

Sub SpecialMsg(n As String) If n = "Label1" Then

MsgBox "You must change the name." End If End Sub

2. Add a breakpoint at the following statement: SpecialMsg myName

3. Place the insertion point anywhere within the code of MyProcedure and press F5 to run it. Visual Basic halts execution when it reaches the breakpoint.

4. Press Shift+F8 or choose Debug | Step Over. Visual Basic runs the SpecialMsg procedure, then execution advances to the statement immediately after the call to the SpecialMsg procedure.

5. Press F5 to finish running the procedure without stepping through its code.

Part I

Now suppose you want to execute MyProcedure to the line that calls the SpecialMsg procedure.

6. Click inside the statement SpecialMsg myName.

7. Choose Debug | Run to Cursor. Visual Basic will stop the procedure when it reaches the specified line.

8. Press Shift+F8 to step over the SpecialMsg procedure.

9. Press F5 to execute the rest of the procedure without single stepping.

Stepping over a procedure is particularly useful when you don't want to analyze individual statements inside the called procedure (SpecialMsg).

0 0

Post a comment