Ascendente:
<% MyArray=Array(25,14,20,45,25,4,1,31,22,7) max=ubound(MyArray) For i=0 to max For j=i 1 to max if MyArray(i) & MyArray(j) then TemporalVariable=MyArray(i) MyArray(i)=MyArray(j) MyArray(j)=TemporalVariable end if next next Response.write ("Los valores serían: <br>") For i=0 to max Response.write (MyArray(i) & "<br>") next %>
El resultado:
Los valores serían: 1 4 7 14 20 22 25 25 31 45
Descendente:
<% MyArray=Array(25,14,20,45,25,4,1,31,22,7) max=ubound(MyArray) For i=0 to max For j=i 1 to max if MyArray(i) & MyArray(j) then TemporalVariable=MyArray(i) MyArray(i)=MyArray(j) MyArray(j)=TemporalVariable end if next next Response.write ("The sorted values are those ones: <br>") For i=0 to max Response.write (MyArray(i) & "<br>") next %>
El resultado:
Los valores serían: 45 31 25 22 20 14 7 4 1
Otro ejemplo, utilizando un función:
function sortArray(arrShort) for i = UBound(arrShort) - 1 To 0 Step -1 for j= 0 to i if arrShort(j)>arrShort(j+1) then temp=arrShort(j+1) arrShort(j+1)=arrShort(j) arrShort(j)=temp end if next next sortArray = arrShort end function
Se utilizaría de la siguiente forma:
dim Friends(3) Friends(0) = "Mary" Friends(1) = "Bill" Friends(2) = "Charlie" AlphaFriends = sortArray(Friends)