0

我有一个二维数组。一维是日期,另一维是名称。

我正在尝试按最新日期对这些数组值进行排序。

我看了几个例子,我想出了这个。

但是日期没有正确排序。

    DataMax = uBound(sDateArray)-1

For i = 0 to DataMax
    For j = i + 1 to DataMax 
        If DateDiff("s", DataArray(j, 0), DataArray(i, 0)) > 0 Then
            TemporalVariable    =   sDateArray(i, 0)
            sDateArray(i, 0)        =   sDateArray(j, 0)
            sDateArray(j, 0)        =   TemporalVariable
        End If
    Next 
Next


    For i=0 to DataMax
      Response.write (sDateArray(i) & "<BR>") 
    next 
4

3 回答 3

0

本文展示了经典 ASP 中的排序:http ://www.4guysfromrolla.com/webtech/062701-1.shtml

总之,这是排序部分(只需将字符串比较替换为日期比较):

Sub SortArray(aTempArray) 
  Dim iTemp, jTemp, strTemp

  For iTemp = 0 To UBound(aTempArray)  
    For jTemp = 0 To iTemp  

      If strComp(aTempArray(jTemp), aTempArray(iTemp)) > 0 Then
        'Swap the array positions
        strTemp = aTempArray(jTemp) 
        aTempArray(jTemp) = aTempArray(iTemp) 
        aTempArray(iTemp) = strTemp 
      End If 

    Next 
  Next 
End Sub
于 2012-06-04T15:49:33.777 回答
0

我实际上找到了一个在线示例。它不是一个功能,它是一个子,但它工作正常。其他建议总是受欢迎的。

Sub DataSorter(arrArray)
    Dim row, j, StartingKeyValue, StartingOtherValue, _
        NewStartingKey, NewStartingOther, _
        swap_pos

    For row = 0 To UBound(arrArray)-1
        StartingKeyValue = arrArray(row, 0)
        StartingOtherValue = arrArray(row, 0)
        NewStartingKey = arrArray(row, 0)
        NewStartingOther = arrArray(row, 0)
        swap_pos = row
        For j = row + 1 to UBound(arrArray)
            If arrArray(j, 0) > NewStartingKey Then
                swap_pos = j
                NewStartingKey = arrArray(j, 0)
                NewStartingOther = arrArray(j, 0)
            End If
        Next    
        If swap_pos <> row Then
            arrArray (swap_pos, 0) = StartingKeyValue
            arrArray (swap_pos, 0) = StartingOtherValue            
            arrArray (row, 0) = NewStartingKey
            arrArray (row, 0) = NewStartingOther     
        End If  
    Next
End Sub
于 2012-06-04T19:14:25.027 回答
-1

该循环不是正确的排序算法。

http://en.wikipedia.org/wiki/Sorting_algorithm

于 2012-06-04T15:11:57.333 回答