[英]Specific sorting of a multidimensional array
I'm currently translating a VBA project into VB.NET. 我目前正在将VBA项目转换为VB.NET。 And I have a little issue with the sorting of a datatable.
我对数据表的排序有一点问题。
My table look like : 我的桌子看起来像:
... | ... | Firstname3 | Name3 | Pay3 | Firstname1 | Name1 | Pay1 | Firstname2 | Name2 | Pay2 |...
... | ... | Firstname2 | Name2 | Pay2 | Firstname3 | Name3 | Pay3 | Firstname1 | Name1 | Pay1 |...
And so on... I export the 56 columns needed from the datatable into an array and try to sort it horizontaly on the Name. 依此类推...我将数据表所需的56列导出到数组中,并尝试在Name上对它们进行水平排序。 I did it that way in VBA :
我是在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
But when I convert the code into VB.NET it doesn't work properly. 但是,当我将代码转换为VB.NET时,它无法正常工作。 Does anyone can explain me why?
谁能解释我为什么? Because in excel it work perfectly.
因为在excel中它可以完美地工作。
Take this example; 举这个例子;
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
This wil automaticly sort the 'extension'. 这将自动对“扩展名”进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.