Click to See Complete Forum and Search --> : Average?


little_boy
November 19th, 2004, 07:27 AM
hi all does someone know how to work an average out....using a list box...its getting me confused...it needs to work out the total of all the numbers entered and divide by itself....

thanks

DeepButi
November 19th, 2004, 08:30 AM
little_boy,
assuming your last post example, something like this
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim d As Double
d = 0
For i = 0 To ListBox1.Items.Count - 1
If CDbl(ListBox1.Items(i)) >= CDbl(TextBox1.Text) AndAlso CDbl(ListBox1.Items(i)) <= CDbl(TextBox2.Text) Then
ListBox2.Items.Add(ListBox1.Items(i))
d += CDbl(ListBox1.Items(i))
End If
Next i
ListBox2.Items.Add("Average: " + CStr(d / ListBox2.Items.Count))

End Sub

Hope it helps (rate the post if it does)

little_boy
November 19th, 2004, 09:29 AM
thanks works lovely to what i want....

thanks again