0

我目前正在将一个 VBA 项目翻译成 VB.NET。我对数据表的排序有一点问题。

我的桌子看起来像:

... | ... | Firstname3 | Name3 | Pay3 | Firstname1 | Name1 | Pay1 | Firstname2 | Name2 | Pay2 |...
... | ... | Firstname2 | Name2 | Pay2 | Firstname3 | Name3 | Pay3 | Firstname1 | Name1 | Pay1 |...

依此类推...我将数据表中所需的 56 列导出到一个数组中,并尝试在名称上对其进行水平排序。我在 VBA 中这样做了:

Public Sub SortTable(ByRef aggTab(,) As Object, ByVal columnToSortOn As Integer, ByVal lowerValue As Byte,
                    ByVal upperValue As Byte)

    Dim ref As Object = aggTab((lowerValue + upperValue) \ 2, columnToSortOn)
    Dim refLowerValue As Byte = lowerValue
    Dim refUpperValue As Byte = upperValue
    Dim temp As Object

    Do
        Do While aggTab(refLowerValue, columnToSortOn) < ref
            refLowerValue = refLowerValue + 1
        Loop
        Do While ref < aggTab(refUpperValue, columnToSortOn)
            refUpperValue = refUpperValue - 1
        Loop
        If refLowerValue <= refUpperValue Then
            For i = LBound(aggTab, 2) To UBound(aggTab, 2)
                temp = aggTab(refLowerValue, i)
                aggTab(refLowerValue, i) = aggTab(refUpperValue, i)
                aggTab(refUpperValue, i) = temp
            Next i
            refLowerValue = refLowerValue + 1 : refUpperValue = refUpperValue - 1
        End If
    Loop While refLowerValue <= refUpperValue

    If refLowerValue < upperValue Then Call SortTable(aggTab, columnToSortOn, refLowerValue, upperValue)
    If lowerValue < refUpperValue Then Call SortTable(aggTab, columnToSortOn, lowerValue, refUpperValue)
End Sub

但是当我将代码转换为 VB.NET 时,它无法正常工作。有谁可以解释我为什么?因为在excel中它工作得很好。

4

1 回答 1

1

举个例子;

    Dim openWith As New SortedDictionary(Of String, String)

    ' Add some elements to the dictionary. There are no  
    ' duplicate keys, but some of the values are duplicates.
    openWith.Add("txt", "notepad.exe")
    openWith.Add("bmp", "paint.exe")
    openWith.Add("dib", "paint.exe")
    openWith.Add("rtf", "wordpad.exe")

    For Each Ext As KeyValuePair(Of String, String) In openWith
        TextBox1.AppendText(Ext.Key & " " & Ext.Value & vbCrLf)
    Next

这将自动对“扩展名”进行排序。

于 2013-08-13T10:04:31.137 回答