Good evening, I’ve looked in all the tutorials and don’t find an answer for this. I have a list box with three columns and three rows. There are numbers in most of the dells. When I add (sum) the numbers as rows I get a number that agrees when I add the numbers individually as a check. When I sum the numbers as columns my number does not agree with the answer the program is giving. I’m off by 1.35 on 6,123.33, 1.16 on 5,832.16 and 1.49 on 11,955.49 which mean little except that the errors aren’t huge but still errors I didn’t expect.
So adding across as rows provides a correct answer all three times, but adding down gives errors. Would anyone know why this is happening? I am using numbers that I enter as general numbers, not currency, to the second place after the decimal.
Any information would be greatly appreciated. Thank you.
I did originally use Val but changed to CDbl . The code I used is this:
// All recordSets have been added to the CalculationsLB and must be tallied to provide
// a total to be placed in the appropriate cell of the ExpensesLB
Dim total as Double
For i = 0 to CalculationsLB.LastRowIndex
total = total + CDbl(CalculationsLB.Cell(i,4))
Next
I hadn’t noticed it before now but the totals for the adding of the columns all end in a number with adouble zero after the decimal which is incorrect. These numbers are also CDbl. Does this help?
AlbertoD, appreciate your efforts. I’ll have to try making a small sample project. Never have done one so kindly give me time. Wasn’t aware that what I sent would show as it did. Was different when I sent.
I created a window with a listbox.
Listbox had 3 columns
In the Open event, I populated the listbox with your data above, then summed the first two columns into the third.
And put the grand total at the end.
Is there something wrong with the values?
(bear in mind that 6,122.00 + 5,831.00 is not 19,954.00 … unsure what is happening in your data?)
dim lb as listbox = self.listbox1
lb.addrow ""
lb.cell(lb.LastAddedRowIndex,0) = "325.49"
lb.addrow ""
lb.cell(lb.LastAddedRowIndex,0) = "3,245.62"
lb.cell(lb.LastAddedRowIndex,1) = "3,245.62"
lb.addrow ""
lb.cell(lb.LastAddedRowIndex,0) = "2,552.22"
lb.cell(lb.LastAddedRowIndex,1) = "2,552.22"
lb.addrow ""
lb.cell(lb.LastAddedRowIndex,0) = "34.32"
lb.addrow ""
lb.cell(lb.LastAddedRowIndex,0) = "6,122.00"
lb.cell(lb.LastAddedRowIndex,1) = "5,831.00"
dim x as integer
dim subtot as double
dim runtot as double
for x = 0 to lb.LastRowIndex
subtot = cdbl(lb.cell(x,0)) + cdbl(lb.cell(x,1))
runtot = runtot + subtot
lb.cell(x,2) = format(subtot,"0.00")
next
lb.addrow ""
lb.cell(lb.LastAddedRowIndex,2) = format(runtot,"0.00")