Ordering arrays

1. Junior Member
Join Date
Dec 1969
Posts
6

## Ordering arrays

How can I order an array, for example if I want to find the three highest scores i.e. if the array contains the scores 2, 5, 3, 7, 5, 9, 4, 12? I want to order the array so that the highest score will be at index 0 and the lowest o be at index 7, please someone help me with this.<BR><BR>cheers<BR><BR>AJ

2. Leo
Senior Member
Join Date
Dec 1969
Posts
1,019

## FAQ #89 & #67

http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=89<BR><BR>http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=67

3. Junior Member
Join Date
Dec 1969
Posts
7

## RE: Ordering arrays

Put this in an asp page:<BR>Function InsertSort(ValueList, Optional SortDescending)<BR>Dim RipVal<BR>Dim RipOrdinal<BR>Dim RipDescent<BR>Dim PrivateBuffer<BR>Dim Placed<BR>Dim x<BR>Dim y<BR>PrivateBuffer = ValueList<BR>RipOrdinal = 1<BR>RipDescent = 1<BR> For y = 1 To UBound(PrivateBuffer)<BR> RipVal = PrivateBuffer(y)<BR> If y &#060;&#062; 1 Then RipDescent = y<BR> Do Until Placed<BR> If IIf(SortDescending, (PrivateBuffer(RipDescent - 1) &#060;= RipVal), (PrivateBuffer(RipDescent - 1) &#062;= RipVal)) Then<BR> RipDescent = RipDescent - 1<BR> If RipDescent = 0 Then<BR> For x = y To RipDescent Step -1<BR> If x = 0 Then Exit For<BR> PrivateBuffer(x) = PrivateBuffer(x - 1)<BR> Next x<BR> PrivateBuffer(RipDescent) = RipVal<BR> Placed = True<BR> End If<BR> Else<BR> For x = y To RipDescent Step -1<BR> If x = 0 Then Exit For<BR> PrivateBuffer(x) = PrivateBuffer(x - 1)<BR> Next x<BR> PrivateBuffer(RipDescent) = RipVal<BR> Placed = True<BR> End If<BR> Loop<BR> Placed = False<BR> Next y<BR>InsertSortAscending = PrivateBuffer<BR>End Function<BR><BR><BR><BR>Now you can include that asp page and use this syntax:<BR><BR>Newarray = insertsort(ValueList, [SortDescending])<BR><BR>PART:---------------DESCRIPTION:<BR>__________________________________ _________________________<BR>Newarray------------Required. A variable that will hold the sorted array<BR>_________________________________________ __________________<BR>ValueList-----------Required. The unsorted array.<BR>________________________________________ ___________________<BR>Sort Descending-----Optional. The array will be sorted in highest to lowest if you want to reverse that set this to true.<BR>_________________________________________ __________________

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•