如何在vb宏中交换整数数组的值和索引
i(0 to 5) = {3,4,1,5,0,2}
To
i(0 to 5) = {4,2,5,0,1,3}
...编辑
谢谢@Tim和@Cody
以下函数是我所拥有的,但是在使用/不使用数组时寻找更好,更有效的方法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
答案 0 :(得分:0)
试试这个
Dim Result As Integer()
ReDim Result(5)
For iLoop = 0 To 5
Result(i(iLoop)) = iLoop
Next