Chapter 6: Debugging with Visual Studio

173

look at is much fewer and you can save time. If you have multiple records, you can press F5 and the breakpoint will pause on each record, allowing you to inspect the value. In this case, the record set is so small that we hit the right record immediately.

7.Press F10 to step over the if condition. This will tell us whether the condition is being evaluated properly. In this case, VS does not step into the if statement but instead moves to the end of the if statement, meaning that searchName and cust.FirstName are not equal. This means you need to take a closer look at cust.FirstName to see what the problem is with the data.

8.Next, we’ll use a couple of the VS debugger tools to inspect cust.FirstName and find out why the equality check is not working. Open the Immediate window (CTRL-D, I) and execute the following expression:

cust.FirstName

which will return this:

"Jean "

Here, you can see that the result has a trailing space—dirty data. Clearly, “Jean” does not equal “Jean ” because of the extra character in the data. There are various non- printable characters that could show up, and VS can help here too.

9.Open a Memory window (CTRL-D, Y), type cust.FirstName into the Address box, and press ENTER. This will show the hexadecimal representation of the data at the memory location of the variable, shown in Figure 6-16.

The layout of the Memory window starts with an address on the left, which is scrolled down to the line where the data in cust.FirstName variable first appears. In the middle is the hex representation of the data. The final column has a readable

Figure 6-16 The Memory window

Page 196
Image 196
Microsoft 9GD00001 manual 173, The Memory window