|
-
May 11th, 2004, 09:36 PM
#1
Thread Starter
New Member
looping through listbox items...
Hello, I am trying to loop through integer values of a list box and sum all the values. I have a class library where I set "mylist" to be a class which inherits the listbox controls. The function returns the first time I add something but only the first time.
This code is in my main form to call the function when a new value is added to the list box and display it in a textbox named txtSum:
txtSum.Text = Mylist1.addEm():
My function is as follows:
Public Function addEm()
Dim i As Integer
Dim total As Integer
With MyBase.Items
For i = 0 To .Count - 1
total += .Item(i)
Return total
Next
End With
End Function
Any insight is appreciated
-Garrett
-
May 11th, 2004, 10:05 PM
#2
Sleep mode
Get the return keyword out of the loop , and you can return the total when you're doing with looping .
-
May 12th, 2004, 04:24 PM
#3
Thread Starter
New Member
Thanks, that fixed my problem.
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
|