Trying to build a calculator for a class assignment that adds numbers from a user input listbox also have a multiply button, below is my code but no matter what I change the math does not seem to work. Any assistance would be greatly appreciated.
Public Class ArithmeticCalculator
Private Property operands As Integer
Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click
Dim operand As Integer
If enterOperandTextBox.Text <> String.Empty Then
OperandsListBox1.Items.Add(enterOperandTextBox.Text)
OperandsListBox1.ClearSelected()
enterOperandTextBox.Clear()
End If
operand = 0
If OperandsListBox1.Items.Count = 0 Then
enterButton.Enabled = True
addButton.Enabled = False
multiplyButton.Enabled = False
End If
End Sub
Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
Dim result As Integer
Dim operandCounter As Integer
result = 0
operandCounter = 0
Do While operandCounter < OperandsListBox1.Items.Count
result = OperandsListBox1.Items(operands)
result += operands
operandCounter += 1
Loop
If operandCounter <> 0 Then result = result + OperandsListBox1.Items.Count
resultLabel.Text = result
End Sub
Private Sub multiplyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multiplyButton.Click
Dim result As Integer
Dim operandCounter As Integer
result = 0
operandCounter = 0
Do While operandCounter < OperandsListBox1.Items.Count
result = OperandsListBox1.Items(operands)
result += operands
operandCounter += 1
Loop
If operandCounter <> 0 Then result = result * OperandsListBox1.Items.Count
resultLabel.Text = result
End Sub
End Class
Public Class ArithmeticCalculator
Private Property operands As Integer
Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click
Dim operand As Integer
If enterOperandTextBox.Text <> String.Empty Then
OperandsListBox1.Items.Add(enterOperandTextBox.Text)
OperandsListBox1.ClearSelected()
enterOperandTextBox.Clear()
End If
operand = 0
If OperandsListBox1.Items.Count = 0 Then
enterButton.Enabled = True
addButton.Enabled = False
multiplyButton.Enabled = False
End If
End Sub
Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click
Dim result As Integer
Dim operandCounter As Integer
result = 0
operandCounter = 0
Do While operandCounter < OperandsListBox1.Items.Count
result = OperandsListBox1.Items(operands)
result += operands
operandCounter += 1
Loop
If operandCounter <> 0 Then result = result + OperandsListBox1.Items.Count
resultLabel.Text = result
End Sub
Private Sub multiplyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multiplyButton.Click
Dim result As Integer
Dim operandCounter As Integer
result = 0
operandCounter = 0
Do While operandCounter < OperandsListBox1.Items.Count
result = OperandsListBox1.Items(operands)
result += operands
operandCounter += 1
Loop
If operandCounter <> 0 Then result = result * OperandsListBox1.Items.Count
resultLabel.Text = result
End Sub
End Class