CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Average?

  1. #1
    Join Date
    Sep 2002
    Posts
    10

    Unhappy Average?

    hi all does someone know how to work an average out....using a list box...its getting me confused...it needs to work out the total of all the numbers entered and divide by itself....

    thanks
    ------------------------------------------------
    -DOES IT ALL SOMETIMES GET A BIT CONFUSING-
    ------------------------------------------------

  2. #2
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Average?

    little_boy,
    assuming your last post example, something like this
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim i As Integer
            Dim d As Double
            d = 0
            For i = 0 To ListBox1.Items.Count - 1
                If CDbl(ListBox1.Items(i)) >= CDbl(TextBox1.Text) AndAlso CDbl(ListBox1.Items(i)) <= CDbl(TextBox2.Text) Then
                    ListBox2.Items.Add(ListBox1.Items(i))
                    d += CDbl(ListBox1.Items(i))
                End If
            Next i
            ListBox2.Items.Add("Average: " + CStr(d / ListBox2.Items.Count))
    
    End Sub
    Hope it helps (rate the post if it does)
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  3. #3
    Join Date
    Sep 2002
    Posts
    10

    Talking Re: Average?

    thanks works lovely to what i want....

    thanks again
    ------------------------------------------------
    -DOES IT ALL SOMETIMES GET A BIT CONFUSING-
    ------------------------------------------------

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