Set a Simple Breakpoint Condition

Tips Search

Set a Simple Breakpoint Condition

  • Comments 5

Menu:  [Right-Click the Breakpoint] -> Condition
Versions:  2008,2010
Published:  5/3/2010
Code:  vstipDebug0021

 

image  

 

Did you know you can set Conditional Breakpoints?  They are arguably the most powerful among the types of Breakpoints you can set.  There are many layers to using them correctly and knowing is half the battle.

 

Let's start with the Breakpoint Condition dialog.  Notice that the condition can be turned off by unchecking the Condition checkbox.  Additionally, there are two options for the condition that you set:

"Is true" is used for Boolean expressions that evaluate to true or false. 

"Has changed" means what it says - if the expression changes then the code stops.

image 

 

 

Suppose I have this "for" loop:

image

 

 

"Is true"

I can set a simple "Is true" condition that says when the variable "i" is greater than, say, 5 the code should stop:

image

 

When I run the code and the Breakpoint is hit, sure enough, it stops when the value of "i" is greater than 5:

image 

 

 

"Has changed"

This one is more interesting.  Basically you set up something to watch.  In this case, I'll just have it watch the "i" variable:

image

 

When the Breakpoint is hit and the value of "i" has changed in in any way then the code stops:

image

 

 

Special Notes

Anytime you set an advanced Breakpoint you will get a new glyph:

image

 

You can always tell what kind of breakpoint you have by looking placing your mouse over the glyph and looking at the tooltip:

image

 

Or checking out the Breakpoints window:

image

  • I don't use these often but when I do I'm glad they're there.

  • VBA has had this feature forever. It's about time that VS finally caught up. Everything old is new again...

  • Well, to be fair, this feature has been around for a bajillion years but it's still one of the cooler ones.

    Z

  • Looks a great article - only the images are all missing.

    Opening one of the images in a new tab just gets you a 500 error.

    Can you fix please?

  • Hey Adam,

    It looks like there was some kind of problem with the MSDN blogs. I'm looking into it to see if it was just my blog or something bigger.

    Z

Page 1 of 1 (5 items)
Leave a Comment
  • Please add 2 and 3 and type the answer here:
  • Post