+1 vote
in Other by
How to swap an integer array's value and index in vb macro

i(0 to 5) = {3,4,1,5,0,2}

To

i(0 to 5) = {4,2,5,0,1,3}

editing...

Thankyou @Tim and @Cody

The following function is what i have got, but looking for better and more efficent ways to do it with/without the array l_aiOldIndexSwap

    Public Function SortValuePairs(ByRef l_aiValues() As Integer) As Integer()

     Dim l_aiOldIndexSwap() As Integer

     ReDim l_aiOldIndexSwap(LBound(l_aiValues) To UBound(l_aiValues))

     For i = LBound(l_aiValues) To UBound(l_aiValues)

      l_aiOldIndexSwap(l_aiValues(i)) = i

     Next

     SortValuePairs = l_aiOldIndexSwap

    End Function

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Try this

Dim Result As Integer()

ReDim Result(5)

For iLoop = 0 To 5

    Result(i(iLoop)) = iLoop

Next
...