2014-02-24 89 views
1

所以我有一个2d数组,我想排序。一维时我可以很容易地排序。 我希望你能帮助我。排序二维数组asp经典

这是我的数据。

top5(0,0) = Greeting 
top5(0,1) = 2 
top5(1,0) = VerifyingInformation 
top5(1,1) = 5 
top5(2,0) = Calibration 
top5(2,1) = 4 

我可以排序它一维时没有问题。 我正在使用此代码的一维。

For i = LBound(top5) to UBound(top5) 
     For j = LBound(top5) to UBound(top5) - 1 
       If top5(j,1) < top5(j + 1,1) Then 
       TempValue = top5(j + 1,1) 
       top5(j + 1,1) = top5(j,1) 
       top5(j,1) = TempValue 
       End If 
      next 
     Next 

我想要的结果就是这个。

VerifyingInformation 5 
Calibration 4 
Greeting 2 
+0

它是正确的,你想根据自己的相关数值,把文本值按降序排列? – nvuono

+0

是的,先生,这是我想要做的。 –

回答

1

它看起来像你实际上只是凑凑热闹执行与相关的文本字符串数值的一维排序。

您的示例代码很接近,但您需要2个临时值来表示您将要移动的数组值。

 For i = LBound(top5) to UBound(top5) 
      For j = LBound(top5) to UBound(top5) - 1 
       If top5(j,1) < top5(j + 1,1) Then 
       TempValue = top5(j + 1,1) 
       TempText = top5(j + 1,0) 
       top5(j + 1,1) = top5(j,1) 
       top5(j + 1,0) = top5(j,0) 
       top5(j,1) = TempValue 
       top5(j,0) = TempText 
       End If 
      Next 
     Next 
+0

谢谢先生。有用。 :) –

1

这工作对我

function sort_arr_mult(byref ArrTmp, ordPlace) 
    ' ordPlace - the place of the order value in the array 
    ' create the new array 
    Redim arrRet (Ubound(ArrTmp, 1), Ubound(ArrTmp, 2)) 

for j = 0 to Ubound(ArrTmp, 2) 
    orderVal = ArrTmp(ordPlace, j) 

    if j = 0 then ' first enter insert to first column 
     for i = 0 to Ubound(ArrTmp, 1) 
      arrRet(i, j) = ArrTmp(i, j) 
     next 
    else    
     ' check the first value if smaller or equal 
     ' move the columnbs one field up 
     ' at the end insert to currenct column 
     for k = 0 to Ubound(arrRet, 2) 
      if isEmp(arrRet(0, k)) then ' if empty fied the column     
       for i = 0 to Ubound(arrRet, 1) 
        arrRet(i, k) = ArrTmp(i, j) 
       next 

       exit for 
      else 
       if orderVal<=arrRet(ordPlace, k) then      
        for x = Ubound(arrRet, 2) to k+1 step -1        
         for i = 0 to Ubound(arrRet, 1) 
          arrRet(i, x) = arrRet(i, x-1) 
         next 
        next 

        for i = 0 to Ubound(arrRet, 1) 
         arrRet(i, k) = ArrTmp(i, j) 
        next 

        exit for 
       end if 
      end if 
     next ' for k = 0 to Ubound(arrRet, 2) 
    end if 
next 

sort_arr_mult = arrRet 
end function