|
-
Apr 16th, 2001, 12:45 PM
#1
Thread Starter
New Member
Hi i have a list box that gets items added to it, the items that are added are numbers. Once i have finished adding the numbers i need a function to total the listbox numbers up.
Please note i need this to work in any number of items within the list box.
Thanks for all you help.
James
-
Apr 16th, 2001, 01:31 PM
#2
Frenzied Member
Code:
Private Function listsum(list As ListBox)
Dim i As Integer
Dim sum As Long
For i = 0 To list.ListCount
sum = sum + Val(list.list(i))
Next i
listsum = sum
End Function
Usage
Code:
dim sum as long
sum = listsum(list1)
-
Apr 16th, 2001, 01:37 PM
#3
Thread Starter
New Member
Dont understand?
Hi sorry could you write it in a command button for me im not sure what usage etc is?
Thanks
Private Sub cmd1_Click()
what goes in here?
End Sub
-
Apr 16th, 2001, 06:30 PM
#4
Frenzied Member
Total newbie, a. No problem. Put this into the general section of the code.
Code:
Private Function listsum(list As ListBox)
Dim i As Integer
Dim sum As Long
For i = 0 To list.ListCount
sum = sum + Val(list.list(i))
Next i
listsum = sum
End Function
Under button click event
Code:
Private Sub cmd1_Click()
dim sum as long
sum = listsum(nameofyourlistbox)
End Sub
-
Apr 16th, 2001, 06:31 PM
#5
Frenzied Member
Or if you don't want to use a function:
Code:
Private Sub cmd1_Click()
Dim i As Integer
Dim sum As Long
For i = 0 To list.ListCount
sum = sum + Val(list.list(i))
Next i
'sum contains sum
End Sub
-
Apr 17th, 2001, 03:50 AM
#6
Thread Starter
New Member
Brilll!!!!!!
Thats great i was totalling the list every time something was added to not not all in one go. Your a star!!! I love VB and i have only been learning it at university a week!!!
James
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|