Access Tip of the Day |
|||
Monitor a procedure's changing values (Access 97/2000/2002) As you debug a procedure, it's often important to understand what types of modifications are being made to a variable value or property. There are a number of ways to keep track of a changing value. One tool that frequently gets overlooked is the Watch Window. This feature lets you define an expression that you want to monitor, such as a calculation based on volatile data or a variable whose contents are frequently updated. When you examine the code in break mode, you can see how the value changes as you step through the procedure. To demonstrate how to use a watch expression, add the following code to a new module: Sub WatchTest() Dim str As String str = "hello" str = str & " world" str = StrConv(str, vbProperCase) str = str & "!" End Sub Then, select any of the occurrences of the str variable in your code and choose Debug | Add Watch from the menu bar. Notice that the Expression text box is automatically filled with whatever text was selected in the code window. You could also enter an object property, function, or custom expression, but just except the default for this simple example. Note that you can specify which procedures and modules the watch should apply to using the controls in the Context panel. The Watch Type panel provides three choices of how the watch results should be displayed: Watch Expression Break When Value Is True Break When Value Changes The first choice continually monitors the expression regardless of any conditions, and the remaining choices should be self-explanatory. For our example, choose the Break When Value Changes option and click OK. If it wasn't already visible, the Watch Window appears and displays details about the watches that have been set up. Because the WatchTest procedure isn't running, the Value and Type information is unavailable. At this point, run the WatchTest procedure. The procedure execution stops as soon as the procedure attempts to change str's initially stored value. Press [F8] to step through the code and you'll see that the str watch updates appropriately as each change is made. To remove a watch that's no longer needed, select it and press the [Delete] key. (Content provided by Element K Journals) (Note: Your browser is set to refuse cookies. As a result, you may frequently see previously-viewed tips)
|
|||
Copyright © 2001 - 2025 MJ Technologies, LLC. All rights reserved. | |||