Results 1 to 3 of 3

Thread: [RESOLVED] Find the average value of a listbox

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Resolved [RESOLVED] Find the average value of a listbox

    Hi there everyone. I am working on a math program to record students answers to a program. I am looking into getting the average value from a listbox of answers called AnswerList.

    Basically, I am wondering how to add up the listbox items because they are all numbers, and then divide by the number of items in the listbox. Would anyone know how I can do that?


    Thanks a lot!

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Find the average value of a listbox

    This code for example will add up the total sum of the items in the listbox.
    VB Code:
    1. Dim I As Integer
    2.  
    3. Dim tot As Integer
    4. For I = 0 To AnswerList.ListCount - 1
    5. tot = tot + Val(AnswerList.List(I))
    6. Next
    7. MsgBox tot

    But after that, how would I divide by the number of items?

    EdIT: Oh wait, would it just be MsgBox Val(tot / List1.ListCount)?

    That seems to work on my end.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,624

    Re: Find the average value of a listbox

    Solved, then? Now, maybe you can figure out the mean, the median and even a Bell Curve!!!!

    Oh, and make sure you don't dim your average variable as an integer.
    Sam I am (as well as Confused at times).

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