Public Class ArithmeticCalculatorForm Private Sub enterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterButton.Click ' clear the previous calculations If resultLabel.Text <> String.Empty Then resultLabel.Text = String.Empty ListBox1.Items.Clear() addButton.Enabled = False multiplyButton.Enabled = False End If ' display numbers in listbox ListBox1.Items.Add(Val(inputTextBox.Text)) inputTextBox.Clear() 'clears numbers from textbox inputTextBox.Focus() ' puts focus to inputTextBox ' if the listbox 2 numbers entered it enables buttons If ListBox1.Items.Count >= 2 Then addButton.Enabled = True multiplyButton.Enabled = True End If End Sub Private Sub addButton_Click(sender As System.Object, e As System.EventArgs) Handles addButton.Click Dim sum As Double For x As Integer = 0 To ListBox1.Items.Count - 1 sum += (ListBox1.Items(x)) Next resultLabel.Text = sum.ToString End Sub Private Sub multiplyButton_Click(sender As System.Object, e As System.EventArgs) Handles multiplyButton.Click Dim product As Double For x As Integer = 0 To ListBox1.Items.Count - 1 product *= (ListBox1.Items(x)) Next resultLabel.Text = product.ToString End Sub End Class ' ArithmeticCalculatorForm

# Arithmetic Calculator

Page 1 of 1## 5 Replies - 9630 Views - Last Post: 10 April 2013 - 06:36 PM

### #1

# Arithmetic Calculator

Posted 10 April 2013 - 05:51 PM

I am trying to get my multiply button to work, when I enter 2 numbers in a listbox and click the multiply button the result goes into the resultLabel. I enter 5, 5 I should get the result of 25 when I click the button but instead I get 0. I am not sure where the problem is.

##
**Replies To:** Arithmetic Calculator

### #2

## Re: Arithmetic Calculator

Posted 10 April 2013 - 05:54 PM

Put a breakpoint on line 38.. and watch what that for loop is doing.. do you really want it to try and multiply all the numbers in the listbox together?

### #3

## Re: Arithmetic Calculator

Posted 10 April 2013 - 06:15 PM

### #4

## Re: Arithmetic Calculator

Posted 10 April 2013 - 06:23 PM

You are in luck! There's material for that!

http://www.dreaminco...4249-debugging/

http://www.dreaminco...ugging-express/

http://www.dreaminco...4249-debugging/

http://www.dreaminco...ugging-express/

### #5

## Re: Arithmetic Calculator

Posted 10 April 2013 - 06:31 PM

Hello,

your variable (product) is 0 to begin with so, you are trying to multiply the number in the listbox by 0 which is always going to equal 0. (product) should be assigned the first number in the listbox before entering the loop and then the loop should start at the second number in the listbox. Also the numbers in the listbox are actually strings and should be converted to a double before any math functions are done with them or they are assigned to a Double variable. You can do that like this

your variable (product) is 0 to begin with so, you are trying to multiply the number in the listbox by 0 which is always going to equal 0. (product) should be assigned the first number in the listbox before entering the loop and then the loop should start at the second number in the listbox. Also the numbers in the listbox are actually strings and should be converted to a double before any math functions are done with them or they are assigned to a Double variable. You can do that like this

product *= CDbl(ListBox1.Items(x))

This post has been edited by **IronRazer**: 10 April 2013 - 06:34 PM

### #6

## Re: Arithmetic Calculator

Posted 10 April 2013 - 06:36 PM

IronRazer, on 10 April 2013 - 06:31 PM, said:

Hello,

your variable (product) is 0 to begin with so, you are trying to multiply the number in the listbox by 0 which is always going to equal 0. (product) should be assigned the first number in the listbox before entering the loop and then the loop should start at the second number in the listbox. Also the numbers in the listbox are actually strings and should be converted to a double before any math functions are done with them or they are assigned to a Double variable. You can do that like this

your variable (product) is 0 to begin with so, you are trying to multiply the number in the listbox by 0 which is always going to equal 0. (product) should be assigned the first number in the listbox before entering the loop and then the loop should start at the second number in the listbox. Also the numbers in the listbox are actually strings and should be converted to a double before any math functions are done with them or they are assigned to a Double variable. You can do that like this

product *= CDbl(ListBox1.Items(x))

Thanks that worked.

Page 1 of 1