# Arithmetic Calculator

Page 1 of 1

## 5 Replies - 12060 Views - Last Post: 10 April 2013 - 06:36 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=318203&amp;s=6210094325052dad321c4989386581fa&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 stumpy88

Reputation: 0
• Posts: 5
• Joined: 10-April 13

# 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.
```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()
multiplyButton.Enabled = False
End If

' display numbers in listbox
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
multiplyButton.Enabled = True
End If
End Sub

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

```

Is This A Good Question/Topic? 0

## Replies To: Arithmetic Calculator

### #2 modi123_1

• Suitor #2

Reputation: 13953
• Posts: 55,693
• Joined: 12-June 08

## 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 stumpy88

Reputation: 0
• Posts: 5
• Joined: 10-April 13

## Re: Arithmetic Calculator

Posted 10 April 2013 - 06:15 PM

modi123_1, on 10 April 2013 - 05:54 PM, said:

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?

Not sure how to use the debugging tool new at this.

### #4 modi123_1

• Suitor #2

Reputation: 13953
• Posts: 55,693
• Joined: 12-June 08

## 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/

### #5 IronRazer

• Custom Control Freak

Reputation: 1490
• Posts: 3,771
• Joined: 01-February 13

## 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
```product *= CDbl(ListBox1.Items(x))
```

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

### #6 stumpy88

Reputation: 0
• Posts: 5
• Joined: 10-April 13

## 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
```product *= CDbl(ListBox1.Items(x))
```

Thanks that worked.