Is it possible to break execution when a watch variable (not a property, just a normal variable) changes to see where the change occurred? I searched and found this question which relates to properties it seems which is not what I'm looking for.
This variable is used several times in several thousand lines of code, but it is only changed from null
when a problem happens. We are trying to track that problem down.
You can display the Watch window by choosing Watch Window from the View menu. A Watch is an instruction to VBA to pause code when an expression is True or when the variable being watched changes value.
Setting a data breakpoint is as easy as right-clicking on the property you're interested in watching inside the watch, autos, or locals window and selecting “Break when value changes” in the context menu. All data breakpoints are displayed in the Breakpoints window.
Any item of data within a program that a programmer wants to observe when debugging. Watch variables may be viewed while the program runs on its own, is stepped through instruction by instruction or when the program crashes. Setting watch variables is part of the debugging operation in a compiler.
Select the left margin or press F9 next to the line of code you would like to stop at. Run your code or hit Continue (F5) and your program will pause prior to execution at the location you marked.
+
in it to indicate that it is conditionalHowever: frankly, I find the following simpler and much more efficient - especially for fields; say we start with:
string name;
we change it just for now to:
private string __name;
string name {
get { return __name; }
set { __name = value; }
}
and just put a break-point on the set
line. It should still compile, and you can see the change trivially. For more complex cases:
private string __name;
string name {
get { return __name; }
set {
if(__name != value) {
__name = value; // a non-trivial change
}
}
}
and put the breakpoint on the inner-most line; this bypasses code that sets the field without actually changing the value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With