Step Over

Step Into w orks by stepping through a program on line at a time in sequence. However, if one sub calls another, then you might w ant the debugger to step over the called sub. This can be done by using the Step Over option. This means that it will execute the called sub all at once, without stepping through it. As an example, consider the two procedures that are named GetRange and CountRange as shown in Listings 8.1 and 8.2. The purpose of the GetRange procedure is to enable the user to enter a cell range, and the procedure w ould select the cell range on the worksheet. Moreover, the procedure would then call another procedure called CountRange whose purpose would be to output to the user the number of cells in the selected range.

To see how this works, if we examine the GetRange procedure, we see that the user range is obtained by using a range variable, Rng, stored from the InputBox function (line 4). Line 5 then checks to see that the user has selected a range using the If statement. If not, then an " Operation Cancelled" message appears, otherwise the selected range is highlighted on the w orksheet (line 8), and then on line 9, we can see that the CountRange procedure is called. This means that program control will immediately transfer directly to the CountRange procedure. At this point, it is said to ' step into' CountRange (Listing 8.2), and the If TypeName(Selection) = "Range" Then line will be executed, followed by the other lines in the procedure in the sequence. Once this procedure has been completed, control will then return to the GetRange procedure to the point following the transfer to CountRange, i.e., line 10. If we were to click the Step Into button successively during execution, then we would step into each line of both procedures. However, if w e w ere to click the Step Over b utton, then it w ould ' step over' any called procedures during execution. Y ou might use this option, if y ou are confident about the called procedures, but wish to debug the main procedure.

0 0

Post a comment