title: Logic with Visual Basic Calculator
body: <p>I'm working on a simple calculator program. I know that I am missing something.  I've followed steps that have been provided, but I have already pointed out several inconsistencies previously so I am sure that this is the case again or information is just plain "missing".  I have two issues.  One, is that when I press a second number before pressing an operator button, the second (and all consecutive number buttons pressed) concatenates twice.  Meaning, if I press "1" then "2", I get "122".  If I then press "3" I get "12233".  The second problem I have is that I cannot figure out how to code the equal button.  I thought that the variable <code>dblCurrentNumber.ToString()</code> would be what I assign to the <code>Equals_click</code>.  But, that does not work.  I'm not looking for anyone to tell me the answer or complete my assignment for me.  That would defeat the purpose of learning.  I'm just looking for a clue as to what I'm missing.</p>
  
  <pre><code>Option Explicit On
  Option Strict On
  Imports System.Math
  
  Public Class Calculator
      'declare the global variables here
      Dim dblResult As Double 'Stores the result of an operation
      Dim dblCurrentNumber As Double 'Stores the current number in the display
      Dim dblMemory As Double 'Stores a value placed in memory by the user
      Dim blnStartNewNumber As Boolean 'Determines whether a new number should be started in the display
      Dim strLastMathOperator As String 'Stores the operation selected by the user; possible values include Clear, Add, Subtract, Multiply, Divide or Equals
  
  
  '''&lt;summary&gt;
  '''clears the values of all variables
  '''required to reset the calculator
  '''&lt;/summary&gt;
  '''&lt;remarks&gt;none&lt;/remarks&gt;
  Private Sub resetCalculator()
      Me.lblResult.Text = "0"
      dblResult = 0
      strLastMathOperator = "Clear"
      blnStartNewNumber = True
      dblCurrentNumber = 0
  End Sub
  
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      resetCalculator()
  End Sub
  Private Sub btnPower_Click(sender As Object, e As EventArgs) Handles btnPower.Click
      'Clears the values of all variables
      resetCalculator()
  End Sub
  
  Private Sub buildNumber(ByVal strNumber As String)
      lblResult.Text = lblResult.Text &amp; strNumber
      dblCurrentNumber = Convert.ToDouble(lblResult.Text)
      'Should we start a new number or add to an existing number?
      If blnStartNewNumber Then
          'start a new number
          lblResult.Text = strNumber
      Else
          'append to the current number
          lblResult.Text = lblResult.Text &amp; strNumber
      End If
      blnStartNewNumber = False
  End Sub
  
  ''' &lt;summary&gt;
  ''' Applies the last operator to result using current number
  ''' &lt;/summary&gt;
  ''' &lt;param name="strOperation"&gt;the math operation to 
  '''     perform +, -, *, / or clear
  '''&lt;/param&gt;
  
  Private Sub handleOperator(ByVal strOperation As String)
      strLastMathOperator = strOperation
      Select Case strLastMathOperator.ToUpper
          Case "ADD"
              dblResult = dblResult + dblCurrentNumber
          Case "SUBTRACT"
              dblResult = dblResult - dblCurrentNumber
          Case "MULTIPLY"
              dblResult = dblResult * dblCurrentNumber
          Case "DIVIDE"
              dblResult = dblResult / dblCurrentNumber
          Case Else
              dblResult = dblCurrentNumber
      End Select
      'dblCurrentNumber = dblResult
      Me.lblResult.Text = dblCurrentNumber.ToString
      Me.blnStartNewNumber = True
      btnDecimal.Enabled = True
  
  End Sub
  
  Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
      buildNumber("0")
  End Sub
  
  Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
      buildNumber("1")
  End Sub
  
  Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
      buildNumber("2")
  End Sub
  
  Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
      buildNumber("3")
  End Sub
  
  Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
      buildNumber("4")
  End Sub
  
  Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
      buildNumber("5")
  End Sub
  
  Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
      buildNumber("6")
  End Sub
  
  Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click
      buildNumber("7")
  End Sub
  
  Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click
      buildNumber("8")
  End Sub
  
  Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click
      buildNumber("9")
  End Sub
  
  Private Sub btnSquareRoot_Click(sender As Object, e As EventArgs) Handles btnSquareRoot.Click
      dblCurrentNumber = Sqrt(dblCurrentNumber)
      Me.lblResult.Text = Str(dblCurrentNumber)
  End Sub
  
  Private Sub btnPercent_Click(sender As Object, e As EventArgs) Handles btnPercent.Click
      Me.lblResult.Text = Str(dblCurrentNumber / 100)
      dblCurrentNumber = dblCurrentNumber / 100
      blnStartNewNumber = True
  End Sub
  
  Private Sub btnPlusOrMinus_Click(sender As Object, e As EventArgs) Handles btnPlusOrMinus.Click
      dblCurrentNumber = (dblCurrentNumber * (-1))
      Me.lblResult.Text = dblCurrentNumber.ToString()
  End Sub
  
  Private Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.Click
      handleOperator("DIVIDE")
  End Sub
  
  Private Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click
      handleOperator("MULTIPLY")
  End Sub
  
  Private Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.Click
      handleOperator("SUBTRACT")
  End Sub
  
  Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
      handleOperator("ADD")
  End Sub
  
  Private Sub btnEquals_Click(sender As Object, e As EventArgs) Handles btnEquals.Click
      dblCurrentNumber.ToString()
  End Sub
  End Class
  </code></pre>