By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

calculating average from an array

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Start with Split

"Mike D" <Mi***@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
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

Jul 22 '05 #2

P: n/a
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" <Mi***@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
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

Jul 22 '05 #3

P: n/a
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!
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.