How To Set Conditional Breakpoints in the Visual InterDev Debugger (284981)
The information in this article applies to:
- Microsoft Visual InterDev 6.0
This article was previously published under Q284981 SUMMARY
In the Visual InterDev debugger, you can set conditional breakpoints that cause the debugger to break only when certain conditions are true. This feature is useful when you are debugging code that has many possible values and you only want to test for certain values.
MORE INFORMATION
The conditional breakpoint feature of Visual InterDev is implemented differently from the other Microsoft Visual Studio development environments. To set conditional breakpoints in Microsoft Visual Basic, for example, you create a "watch expression" and then set various properties of the expression, such as the context in which it breaks and the value that causes it to break. In Visual InterDev, you cannot set conditions directly on watches, but you can use a different approach for conditional breakpoints.
How to Set Conditional Breakpoints in Visual InterDev
The following Active Server Pages (ASP) sample code loops through an ActiveX Data Objects (ADO) Recordset, which is created from the Pubs sample database in SQL Server, and writes the field values in a table:
<table border=1>
<%
If not (rs.BOF and rs.EOF) then
Do while not rs.eof
Response.write "<TR>" & vbcrlf
Response.write "<TD>" & rs.fields("au_fname") & "</TD>" & vbcrlf
Response.write "<TD>" & rs.fields("au_lname") & "</TD>" & vbcrlf
Response.write "<TD>" & rs.fields("phone") & "</TD>" & vbcrlf
Response.write "</TR>" & vbcrlf
rs.MoveNext
loop
Else
Response.Write "Sorry! No records."
End if
%>
</table>
To trigger a breakpoint when rs.fields("au_fname") evaluates to "Meander", follow these steps:
- Make sure that you view the code in Source View in Visual InterDev.
- Right-click the line of code where you want to set the breakpoint.
- On the context menu, click Insert breakpoint.
- On the Debug menu, click Breakpoints.
- In the Breakpoints dialog box, the breakpoints are distinguished by file name and line number. Select your breakpoint, and then click Properties.
- In the Script Breakpoint Properties dialog box, in the Condition text box, type rs.fields("au_fname") = "Meander", and then click is true.
- Click OK twice to close each dialog box.
After you create the condition, click Start on your toolbar or on the debug menu to launch the debugger. The debugger hits your breakpoint and stops when the condition is true. To verify that the debugger stops when the condition is true, check the value of the field in the Locals window, or type the following code in the Immediate window:
?rs.fields("au_fname")
It is important to remember that you can only put simple, non-evaluative code in the Conditions text box of the Breakpoints dialog box. You cannot enter functions or subroutines, even built-in ones such as the Date function. For example, if you enter the following code
left(rs.Fields("phone"),3) = "801"
in the Conditions text box, you receive an error message, even though this code works when it is executed in the ASP page. If you want to test for such a condition (for example, if you wanted to stop the debugger when the "phone" field has an area code of "801"), follow these steps:
- Declare a variable.
- In a temporary line of code, assign the result of the function to the variable. For example:
SomeVar = left(rs.Fields("phone"),3)
- In the Conditions text box of the Breakpoints dialog box, type SomeVar = '801'.
Modification Type: | Minor | Last Reviewed: | 7/13/2004 |
---|
Keywords: | kbBug kbDebug kbDevStudio kbhowto kbide KB284981 |
---|
|