survey4life
New Member
- Joined
- Oct 25, 2011
- Messages
- 46
I have a listbox with several values which change and i want to add the all the values in that listbox. Here is my code:
The problem with my code is that it doesnt add the decimal values. It rounds up the starting numbers to nearest decimal place and shows result.
For e.g Listbox with the following values: 10.7 + 10.0 + 10.1 = 31.00
which is obviously not correct.
So, can someone please either edit my code or write a fresh code that adds values of a listbox including the decimal values.
Code:
lbTotal.Clear
Dim counter As Integer
Dim sum As Integer
For counter = lbTotal2.ListCount - 1 To 0 Step -1
sum = sum + lbTotal2.List(counter)
Next counter
lbTotal.AddItem Format(sum, "#,##0.00")
The problem with my code is that it doesnt add the decimal values. It rounds up the starting numbers to nearest decimal place and shows result.
For e.g Listbox with the following values: 10.7 + 10.0 + 10.1 = 31.00
which is obviously not correct.
So, can someone please either edit my code or write a fresh code that adds values of a listbox including the decimal values.