array sort

Hi,

Two arrays called:
Dim Arr_ReqConverted() As String   <--this contains the actual values
Dim Arr_First7Highest(6) As Integer   <---this is a index value pointer to Arr_ReqConverted()

how can we re-arrange and sort the arr_first7highest(6) ? re-arrangeing arr_first7highest(6) -highest to lowest

Note:We need to lookup the real value in Arr_ReqConverted() to determine the sort order.

i.e.

Arr_ReqConverted() = 102,201,30,405,50,60,70,80,90,100
Arr_First7Highest(6)=2,4,6,1,9,5,7  
lookup element actual valueArr_ReqConverted(Arr_First7Highest(0))=30
lookup element actual valueArr_ReqConverted(Arr_First7Highest(1))=50
lookup element actual valueArr_ReqConverted(Arr_First7Highest(2))=70
lookup element actual valueArr_ReqConverted(Arr_First7Highest(3))=201
lookup element actual valueArr_ReqConverted(Arr_First7Highest(4))=100
lookup element actual valueArr_ReqConverted(Arr_First7Highest(5))=60
lookup element actual valueArr_ReqConverted(Arr_First7Highest(6)=80

desired output:
Arr_First7Highest(6)=1,9,7,6,5,4,2


currently stuck:
    Dim Best_J As Integer
    Dim J As Integer
    Dim Best_ValueConverted As Integer
    Dim Best_Value As Integer
    For i = 0 To 6 - 1
    Best_ValueConverted = Arr_ReqConverted(Arr_First7Highest(i))
    Best_J = i
        For J = i + 1 To 6
            If Arr_ReqConverted(Arr_First7Highest(J)) > Best_ValueConverted Then
                Best_ValueConverted = Arr_ReqConverted(Arr_First7Highest(J))
                Best_Value = Arr_First7Highest(J)
                Best_J = J
            End If
        Next
       
        Arr_First7Highest(Best_J) = Arr_First7Highest(i)
        Arr_First7Highest(i) = Best_Value2
       
    Next i
RyanBankAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pradapkumarCommented:
It is very difficult to understand ur question. Can u elabrate the above  step by step. So, we can help u appropriately.
RyanBankAuthor Commented:
we need to sort the values in  Arr_First7Highest(6) but inorder to sort properly, we need to lookup the value in Arr_ReqConverted()

i.e.

Arr_ReqConverted() = 102,201,30,405,50,60,70,80,90,100
Arr_First7Highest(6)=2,4,6,1,9,5,7  
lookup element actual valueArr_ReqConverted(Arr_First7Highest(0))=30
lookup element actual valueArr_ReqConverted(Arr_First7Highest(1))=50
lookup element actual valueArr_ReqConverted(Arr_First7Highest(2))=70
lookup element actual valueArr_ReqConverted(Arr_First7Highest(3))=201
lookup element actual valueArr_ReqConverted(Arr_First7Highest(4))=100
lookup element actual valueArr_ReqConverted(Arr_First7Highest(5))=60
lookup element actual valueArr_ReqConverted(Arr_First7Highest(6)=80

desired output:
Arr_First7Highest(6)=1,9,7,6,5,4,2
TimCotteeHead of Software ServicesCommented:
Hi RyanBank,

Dim Arr_ReqConverted() As String   '<--this contains the actual values
Dim Arr_First7Highest() As String   '<---this is a index value pointer to Arr_ReqConverted()

Arr_ReqConverted() = Split("102, 201, 30, 405, 50, 60, 70, 80, 90, 100", ",")
Arr_First7Highest() = Split("2,4,6,1,9,5,7", ",")

Dim blnSorted As Boolean
Dim intElement As Integer
Do
    blnSorted = True
    For intElement = LBound(Arr_First7Highest) To UBound(Arr_First7Highest)
        If intElement > LBound(Arr_First7Highest) Then
            If CInt(Arr_ReqConverted(Arr_First7Highest(intElement))) > CInt(Arr_ReqConverted(Arr_First7Highest(intElement - 1))) Then
                temp = Arr_First7Highest(intElement)
                Arr_First7Highest(intElement) = Arr_First7Highest(intElement - 1)
                Arr_First7Highest(intElement - 1) = temp
                blnSorted = False
            End If
        End If
    Next
Loop Until blnSorted = True
Dim strA As String
For intElement = LBound(Arr_First7Highest) To UBound(Arr_First7Highest)
    strA = strA & Arr_ReqConverted(Arr_First7Highest(intElement)) & vbLf
Next
MsgBox Join(Arr_First7Highest, ",") & vbLf & vbLf & strA

This does the trick.

Tim Cottee

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

RyanBankAuthor Commented:
TimCottee,

Outstanding, works like a charm!

What sorting algorithm is this?

Thanks.
TimCotteeHead of Software ServicesCommented:
RyanBank,

It is a kind of bubble-sort, essentially it switches position of elements that are higher or lower. So it may take more iterations of the loop if the elements are very unsorted to start with but fewer iterations if they are well sorted. Overall it is actually a quick way to sort elements especially with larger arrays.

Tim
TimCotteeHead of Software ServicesCommented:
RyanBank,

What I should point out is that on each iteration it assumes to start with that no switches take place, if we have to switch then we set blnSorted to false so it goes through again. If no switches can take place it is all perfectly sorted and we can exit the loop.

Tim
RyanBankAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.