CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    2

    list box calculations

    Please, I need to know how to total numeric values in a list box and divide that by the list count.


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: list box calculations

    let's assume that your listbox contains only numbers:
    dim iSum as integer
    Dim i as integer
    For i = 0 To List1.ListCount - 1
    isum = isum + List1.List(i)
    Next i
    MsgBox isum / List1.ListCount




  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: list box calculations

    Hi

    Try something like :

    Dim lTot As Long
    Dim lCount As Long

    For lCount = 0 To List1.ListCount - 1
    If IsNumeric(List1.List(lCount)) Then
    lTot = lTot + CLng(List1.List(Count))
    End If
    Next

    MsgBox "Total = " & lTot
    MsgBox "Average = " & lTot / List1.ListCount


    Regards

    Chris Eastwood

    CodeGuru - the website for developers
    http://www.codeguru.com/vb



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

Featured