Toggle Breakpoint the hand icon

There is little point in opening a Watch window, unless you can slow the program operation down enough to get a chance to see what is happening during program execution. A breakpoint does exactly that: it sets a program execution break at a line of code as a point at which the program will pause. It is a forced execution break in the program, and you can set breakpoints wherever you want. Select Toggle Breakpoint on the Debug menu and choose breakpoints carefully, because if, for example, you are Watching a cell in a loop, then clearly a breakpoint would have to be positioned somewhere inside the loop, otherwise it would not achieve its objective.

To remove the breakpoint, select it and use Debug > Toggle Breakpoint.

I Microsoft Visual Basic - SALESMAN.xls [break] - [othersalesmanmacros (Code)]

_|pj Xj

4

File

.Edit View insert Format Debug Run fools Add-Ins Window Help

Type a question for help ▼ _ fi> x

m

! il

-H1 & Mi e, ¿4 | " « ! ► n . M *

S '0 | GJ | Ln 3?, OjH

M, is % SI 11 ^Tb'SH

p Jp Si ..

| (General)

jvalidateWeekSales

d

n

r

Worksheets("Weeklysales").Select Act iveSheet.Unprotect Dim cell As Object

For Each cell In Range("Week sales")

IT

e-

Not IsNumeric(cell) Then

IT

HsgBox "Please Enter a number in cell" & cell.Address With cell.Interior .Colorlndex = 3 .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With

HsgBox "Please enter number between 0 & 100 in Cell" & With cell.Interior

cell.Address

¡Watches ES

Eictares.sipni 1 Vsiue-

|Type

| Context •*•

öi ng cell

ObjectJRange

othersalesmanmacros .validateWeekSa

Figure 8.7 The Breakpoint line (With cell.Interior) and the Watch window.

Figure 8.7 The Breakpoint line (With cell.Interior) and the Watch window.

With regard to the validate WeekSales macro, a good place to set a b reakpoint would be on line If Not IsNumeric(cell) Then. This is because this line is inside the loop and therefore will stop during each loop execution. To turn this line into a b reakpoint, position the cursor over this line and select Toggle Breakpoint from the Debug menu. Note that the line will b e displayed with a brown background colour, indicating that it is a breakpoint. Figure 8.7 shows the breakpoint line in the VBE module window and the Watch window during the first program loop. Notice that the cell value is 54 as expected.

0 0

Responses

Post a comment