0

我知道这个话题以前被打开过很多次。

我看了所有的例子,但我就是不能让它工作!

我有 3 个维度,日期在第一个维度。

一切正常,期待一个数组,我只是不明白为什么..

这是测试链接:点击这里

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)
        StartingVenue = arrArray(row, 1)
        StartingVenueOther = arrArray(row, 1)
        swap_pos = row
        For j = row + 1 to UBound(arrArray)
            If DateDiff("s", arrArray(j, 0), NewStartingKey) < 0 Then
                swap_pos = j
                NewStartingKey = arrArray(j, 0)
                NewStartingOther = arrArray(j, 0)
                NewStartingVenue = arrArray(j, 1)
                NewStartingVenueOther = arrArray(j, 1)
                NewStartingCountry = arrArray(j, 2)
                NewStartingCountryOther = arrArray(j, 2)
            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     
            arrArray (swap_pos, 1) = StartingVenue
            arrArray (swap_pos, 1) = StartingVenueOther  
            arrArray (row, 1) = NewStartingVenue
            arrArray (row, 1) = NewStartingVenueOther   
            arrArray (swap_pos, 2) = StartingCountry
            arrArray (swap_pos, 2) = StartingCountryOther  
            arrArray (row, 2) = NewStartingCountry
            arrArray (row, 2) = NewStartingCountryOther   
        End If  
    Next
End Sub
4

1 回答 1

0

很奇怪的代码。试试这个:

Sub DataSorter(arrArray)
Dim row, i, tmp
For row = 0 To UBound(arrArray) - 1
    For j = row + 1 to UBound(arrArray)
        If DateDiff("s", arrArray(j, 0), arrArray(row, 0)) < 0 Then
            For i = 0 To 2
                tmp = arrArray(j, i)
                arrArray(j, i) = arrArray(row, i)
                arrArray(row, i) = tmp
            Next
        End If
    Next
Next

结束子

于 2013-03-15T04:57:39.907 回答