I found a program at a vb website that did several statisical calculations including Mean(average), Mode and median. I am tring to make a simple program for my kids to check their homework. I have a form with a textbox to enter a set of numbers, which then are added to listbox(one at a time) and once the user clicks the calculate button in three different textboxes are displayed the Mean the(the average of the numbers) and the mode ( the number that appears the most), and in the last textbox the median the number that is the middle number of the set.
example: 10, 10, 15, 17, 20, 25
Mean = 16.16 10 +10+15+ 17+20+25= 97/ 6 = 16.16
Mode= 10 10 , 10 (2 10's)
Median = 16 10, 10, 15 (16) 17, 20 ,25 on even numbers you take the 2 middle number, add them together then divide by 2, odd set of numbers it is the middle number.
Is there any built in functions for these, or how would I go about in creating them.
Thanks.........
Private Function median(lstBox As Control)
If lstBox.ListCount Mod 2 = 1 Then
lstBox.ListIndex = (lstBox.ListCount / 2) - 0.5
median = lstBox.Text
Exit Function
Else
lstBox.ListIndex = (lstBox.ListCount / 2) - 1
sum = Val(lstBox.Text)
lstBox.ListIndex = lstBox.ListIndex + 1
sum = sum + Val(lstBox.Text)
median = sum / 2
End If
End Function
Private Function mean(lstBox As Control)
Dim sum As Long
For i = 0 To lstBox.ListCount - 1
lstBox.ListIndex = i
sum = sum + Val(lstBox.Text)
Next
mean = sum / i
End Function
'Call it a-la
myMean = mean(List1)