In visual studio 2005 (and probably later ones too) there is a little icon that looks like a window with three little windows on top of it. Hovering your mouse over it shows the label "Call Stack". Clicking this at a breakpoint or error will bring up a window at the bottom that shows the whole history of the program up until that point. You can double-click each line to take you to the section of code, and hovering your mouse over any variable should tell you what it equals.
Do this, and you will find the source of your problem.