Getting totals in a list box.

ladynred

Member
Joined
Mar 20, 2006
Messages
5
Programming Experience
Beginner
Hi, I am new at this so I need all the help I can get.
I am working on a program where the user enters a number into a text box. Then they press a button which adds the number to a list box. I have finally got the numbers to total in the list box (by clicking a button to calculate), but then when you click the Remove button, it removes the number from the list box, but does not remove it from the total.
Also, I can't figure out how to return the highest number in the list, the lowest number and the average of the numbers. I want these displayed in labels.
Here is some of my code:
PrivateSub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim I AsInteger
Dim decTotGrade AsDecimal
Dim Grades AsDecimal
Dim Count AsInteger
ForEach I In lstGradeList.Items
decTotGrades += I

Count = Val(lstGradeList.Items.Count)
If Count = Count - 1 Then
decTotGrade -= I
EndIf
Label4.Text = decTotGrades

PrivateSub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
Dim Count AsInteger
Dim I AsInteger
Dim TotGrade AsDecimal
lstGradeList.Items.Remove(lstGradeList.SelectedItem)
Count = Count - 1
If Count = Count - 1 Then
decTotGrades -= I
EndIf

Thanks for the help.



 
cannot understand your code~
i think maybe u do not set the I value.
decTotGrades -= I

To get the higher value.

Dim maxValue as Decimal = Decimal.Parse(lstGradeList.Items(0).Text)
Dim minValue as Decimal = Decimal.Parse(lstGradeList.Items(0).Text)
Dim decTotal as Decimal = 0
Dim decAverage as Decimal = 0
Dim intCount as Integer = Val(lstGradeList.Items.Count)

For Each item As ListViewItem In Me.lstGradeList.Items

If maxValue < Decimal.Parse(item.Text) Then
maxValue = Decimal.Parse(item.Text)
End If

If minValue > Decimal.Parse(item.Text) Then
minValue = Decimal.Parse(item.Text)
End If

decTotal += Decimal.Parse(item.Text)

Next
decAverage = decTotal / intCount

Hope this can help you~
 
RE: List Box

Thanks for your help albertkhor. I had already come up with something similar, but I do appreciate it.

Ladynred
 
Back
Top