List Box in VB 6 (1 Viewer)

acmilan

I'll stab ya
Joined
May 24, 2004
Messages
3,989
Location
Jumanji
Gender
Male
HSC
N/A
If i have a list box with a numerical value in it, is there anyway to add all the numerical values it contains?
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Are you saying a listbox contains a list of values and you want to get the sum of all of it? :S
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
If my assumption is correct here's how you do it, you're basically traversing through the listbox and adding the values, easy:


Public sumOfListBox As Integer

Private Sub cmdSumOfListBox_Click()

'Loops through every item from the beginning of the listbox to the last element
For i = 0 To Me.List1.ListCount - 1

sumOfListBox = sumOfListBox + CInt(Me.List1.List(i))

Next

'Displays the final sum in a message box
MsgBox (sumOfListBox)

End Sub
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top