Velocity Reviews > calculating average from an array

# calculating average from an array

Mike D
Guest
Posts: n/a

 11-19-2004
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
Guest
Posts: n/a

 11-19-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
Guest
Posts: n/a

 11-19-2004

"Mike D" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

dlbjr
Guest
Posts: n/a

 11-19-2004
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