Start New Discussion within our Software Development Community

I'm trying to get the addButton to work correctly in this code, but it keeps only outputing the first number entered, not the sum of the numbers. What am I missing here?

Public Class ArithmeticCalculatorForm
   Dim numCounter As Double = 0
   Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click

      If resultLabel.Text <> "" Then
         resultLabel.Text = ""
         addButton.Enabled = False
         multiplyButton.Enabled = False
      End If

      'display operands in LBox

      If operandListBox.Items.Count < 2 Then
         addButton.Enabled = False
         multiplyButton.Enabled = False
         addButton.Enabled = True
         multiplyButton.Enabled = True
      End If
   End Sub

   Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
      Dim total As Double = 0
      Dim numCounter As Integer = 0
      Dim eachNum As Double = 0

      eachNum = operandListBox.Items.Item(numCounter)
      total += eachNum    'add each number to total
      numCounter += 1

      resultLabel.Text = String.Format("{0:F}", total)
      addButton.Enabled = True            'enable Add Grade button

   End Sub
End Class ' ArithmeticCalculatorForm
This article has been dead for over six months. Start a new discussion instead.