• 0
Sign in to follow this  
marcos_804

Ordernar Array De Forma Crescente...

Question

Pessoal, tem como ordernar uma array de forma crescente em asp?

Já vi isso em javascritp e PHP utilzando uma função "sort".

Tem alguma função que voces conhecam para eu armazenar estes valores em um array e depois chamar de forma crescente ou descrescente em asp...?

Desde já agradeço a atenção.

Marcos Oliveira

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
Guest --Teo --

Function SelectionSort(TempArray, SortOrder)

Dim MaxVal, MaxIndex, i, x

' Step through the elements in the array starting with the last element.

For i = UBound( TempArray) To 0 Step -1

' Set MaxVal to the element in the array and save the

' index of this element as MaxIndex.

MaxVal = TempArray(i)

MaxIndex = i

' Check the selected sortorder of the array

' "<" for DESC and ">" for ASC

If SortOrder = "<" Then

' Loop through the remaining elements to see if any is

' larger than MaxVal. If it is then set this element

' to be the new MaxVal.

For x = 0 To i

If TempArray(x) < MaxVal Then

MaxVal = TempArray(x)

MaxIndex = x

End If

Next

Else

For x = 0 To i

If TempArray(x) > MaxVal Then

MaxVal = TempArray(x)

MaxIndex = x

End If

Next

End If

If MaxIndex < i Then

TempArray(MaxIndex) = TempArray(i)

TempArray(i) = MaxVal

End If

Next

SelectionSort = TempArray

End Function

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this