calculating average from an array

Discussion in 'ASP General' started by Mike D, Nov 19, 2004.

  1. Mike D

    Mike D Guest

    I have an array like

    array = "1,2,3|,2,4,6| ...)

    There will be an unknown number a values between the | and an uknown total
    number of values. I need to get the average of the number between each of
    the |'s. Any ideas how to handle that?

    Mike
    Mike D, Nov 19, 2004
    #1
    1. Advertising

  2. Hello,

    MyNewArray1 = Split (array, "|")
    MyNewArray2 = Split (array, ",")

    With best regards,

    --
    Should you have any questions, please don't hesitate to contact me.
    If you response to an email, please quote the complete message.
    http://1click.lv

    "Mike D" <> wrote in message
    news:...
    > I have an array like
    >
    > array = "1,2,3|,2,4,6| ...)
    >
    > There will be an unknown number a values between the | and an uknown total
    > number of values. I need to get the average of the number between each of
    > the |'s. Any ideas how to handle that?
    >
    > Mike
    Andrew Zamkovoy, Nov 19, 2004
    #2
    1. Advertising

  3. Mike D

    Jeff Dillon Guest

    Start with Split

    "Mike D" <> wrote in message
    news:...
    > I have an array like
    >
    > array = "1,2,3|,2,4,6| ...)
    >
    > There will be an unknown number a values between the | and an uknown total
    > number of values. I need to get the average of the number between each of
    > the |'s. Any ideas how to handle that?
    >
    > Mike
    Jeff Dillon, Nov 19, 2004
    #3
  4. Mike D

    dlbjr Guest

    Function GetUniqueAvg(strData)
    If Len(strData) > 0 Then
    ar1 = Split(strData,"|")
    For i = 0 To UBound(ar1)
    strItem = ar1(i)
    If Len(strItem) > 0 Then
    ar2 = Split(strItem,",")
    intTotal = 0
    For ii = 0 To UBound(ar2)
    If IsNumeric(ar2(ii)) Then
    intTotal = CDbl(intTotal) + CDbl(ar2(ii))
    End If
    Next
    ar1(i) = CDbl(intTotal) / CDbl(UBound(ar2) + 1)
    Else
    ar1(i) = 0
    End If
    Next
    GetUniqueAvg = Join(ar1,",")
    End If
    End Function

    'dlbjr
    'Pleading sagacious indoctrination!
    dlbjr, Nov 19, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven

    AVERAGE SQL error... help please

    Steven, Oct 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,407
    Richard K Bethell
    Oct 16, 2003
  2. GregM

    Calculating average time

    GregM, Jul 7, 2005, in forum: Python
    Replies:
    3
    Views:
    4,616
    Peter Tillotson
    Jul 8, 2005
  3. s4189332

    Calculating average

    s4189332, Mar 18, 2009, in forum: Python
    Replies:
    0
    Views:
    256
    s4189332
    Mar 18, 2009
  4. Erol Akman
    Replies:
    9
    Views:
    217
    Erol Akman
    Mar 25, 2009
  5. ela
    Replies:
    8
    Views:
    197
Loading...

Share This Page