1. Home
  2. Computing & Technology
  3. Visual Basic

ASP.NET - Learn Programming for the Networked World - Part 4

By Dan Mabbutt, About.com

6 of 8

The Calculator Still Doesn't 'Add Up'

Testing the Control

Testing the Control

If you're still with me on this, the page does not generate any errors when try to do a calculation this time. But it doesn't work, either. The illustration shows what you get when you try 2 + 2. Something, literally, "doesn't add up". We know that the logic we're using is correct. It works in the VB.NET version.

To find the problem, we need to dig a little deeper with the debugging tools provided by Visual Studio. One way to begin is to note that the problem involves the Textbox display when an operation key, the "+" key in our test, is pressed. So let's start by setting a "breakpoint" in the "op" and "key_click" subroutines so we can "single step" through these sections of code in our next test.

You might have to do this a few times to prove it to yourself, but you should be able to determine that, although the variable "PendingOpFlag" is set to "True" in the "op" subroutine, the value is "False" again in the subsequent "key_click" event subroutine. In the VB.NET code, these variables are declared outside the subroutines to make them global to all subroutines, but they're behaving like strictly local variables now.

Like many things in programming, the problem is that a completely new condition has been created that the existing code won't handle. The problem was described, in theory, back in the first part of this tutorial, but here's a concrete example. The new condition is "state".

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Learn ASP.NET
  6. ASP.NET - Learn Programming for the Networked World - Part 4

©2009 About.com, a part of The New York Times Company.

All rights reserved.