Results 1 to 3 of 3

Thread: looping through listbox items...

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    3

    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

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Get the return keyword out of the loop , and you can return the total when you're doing with looping .

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    3
    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
  •  



Click Here to Expand Forum to Full Width