472,338 Members | 1,663 Online

# Extract MAX Number from Array

Hello,

I have an array of numbers where I am attempting to extract the highest (max) number in the array. I am pretty new to asp and vbscript and hope to get some help. My code below returns 22 as the max number though it should be 45. can someone direct me in the right direction?

Thanks

MyArray=Array(25,14,20,45,25,4,1,31,22,7)

For i=0 to ubound(MyArray)
For j=i+1 to ubound(MyArray)
if myarray(i) > MyArray(j) then
co = myarray(i)
end if
next
next

'Write the Highest number in MyArray
Response.write co
Nov 13 '06 #1
1 4714
willakawill
1,646 1GB
Hello,

I have an array of numbers where I am attempting to extract the highest (max) number in the array. I am pretty new to asp and vbscript and hope to get some help. My code below returns 22 as the max number though it should be 45. can someone direct me in the right direction?

Thanks

MyArray=Array(25,14,20,45,25,4,1,31,22,7)

For i=0 to ubound(MyArray)
For j=i+1 to ubound(MyArray)
if myarray(i) > MyArray(j) then
co = myarray(i)
end if
next
next

'Write the Highest number in MyArray
Response.write co
Hi. Try this
Expand|Select|Wrap|Line Numbers
1. co = MyArray(0)
2. For i = 1 To UBound(MyArray)
3.    If MyArray(i) > co
4.       co = MyArray(i)
5.    End If
6. Next i
7.
Nov 13 '06 #2