Using Watch Expressions

See Also28XIFU3

There are two ways to watch1Z5654F, or monitor, expressions1DUM8 in Visual Basic.  You can simply watch the value of the expression in the Debug window199M6LF, or you can suspend program execution when the expression is true or changed.

When you watch the value of an expression, you generally set a breakpoint1YXJ0G5 in a procedure in which you want to know the expression's value, and then use the Instant watch command to see the expression's value when program execution is suspended in that procedure.  When you use Instant watch, you have the option of also placing the expression in the Debug window.

You can also use the last two options in the Watch Type group to suspend application execution either when an expression becomes nonzero or each time the expression's value changes from zero to nonzero or from nonzero to zero.  Note that the term "true" when used with watchpoints refers to the logical (nonzero) state true, rather than to the bitwise complement of zero (that is, Not False, expressed as the intrinsic constant True (whose value is always -1).

For example, if you choose the Break When Expression is True option for a variable named MyVar in a procedure, program execution is suspended as soon as MyVar acquires a nonzero value.  However, if you choose it for the expression MyVar > 5, execution is not suspended until the expression MyVar > 5 evaluates to True.  Note that a simple string variable cannot be evaluated by itself; it must be used in a comparative expression like StrVar$ <> "" or be evaluated, as in the function call Len(StrVar$), in order for a watchpoint to suspend execution when it changes from an empty (zero length) to nonempty state.

The Context option for an expression can be no wider than the scope of the components of the expression.  For example, local variables can have only Procedure context.  Expressions whose components are defined at form or module level can have Procedure or Form/Module context, and globally scoped expressions can have any context.


See Also

Help:

Edit Watch CommandXNRDV2

 

Programmer's Guide:

Chapter 9, "Debugging"