# calculating average from an array

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

1. ### Mike DGuest

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

2. ### Andrew ZamkovoyGuest

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

3. ### Jeff DillonGuest

"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
4. ### dlbjrGuest

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