Click to See Complete Forum and Search --> : list box calculations


doddio
April 8th, 1999, 12:04 AM
Please, I need to know how to total numeric values in a list box and divide that by the list count.

Lothar Haensler
April 8th, 1999, 02:24 AM
let's assume that your listbox contains only numbers:
dim iSum as integer
Dim i as integer
For i = 0 To List1.ListCount - 1
isum = isum + List1.List(i)
Next i
MsgBox isum / List1.ListCount

Chris Eastwood
April 8th, 1999, 02:29 AM
Hi

Try something like :

Dim lTot As Long
Dim lCount As Long

For lCount = 0 To List1.ListCount - 1
If IsNumeric(List1.List(lCount)) Then
lTot = lTot + CLng(List1.List(Count))
End If
Next

MsgBox "Total = " & lTot
MsgBox "Average = " & lTot / List1.ListCount


Regards

Chris Eastwood

CodeGuru - the website for developers
http://www.codeguru.com/vb