I am trying to SUM a column in a list box and I’ve used the following and other iterations but none will give an answer other than zero. There are several examples of how to add rows but I cannot find code examples on how to add a row of numbers to provide a total. If someone could provide an example or provide a reference I would appreciate it. Many of the references that I have followed have turned out to be non-existent any longer so I ask for your help. Thank you.
Dim i as integer
Dim total as integer
For i=0 to PurchasesLB.ListCount-1
if PurchasesLB.Selected(i) then
total=total+Val(PurchasesLB.Cell(i, 4))
Dim i As Integer
Dim total As Double // Val and CDbl deliver Doubles, so better use a Double
For i=0 To PurchasesLB.LastRowIndex
// If PurchasesLB.RowSelectedAt(i) Then // Commented out, because only selected Rows would be added
total=total+CDbl(PurchasesLB.CellTextAt(i, 4)) // Use CDbl instead of Val if you need to be international savy
// End If
Next
txtTotal.Text = Format(total, "###,###,##0.00")