我正在使用冒泡排序功能按对象的属性对对象进行排序。不幸的是,我不得不为每个属性编写一个函数。有什么方法可以概括以下功能。
而不是写
SortArticlesByVolume(a)
SortArticlesByLenght(a)
我想写一些类似的东西:
SortArticles(a, volume)
Sub SortArticlesByVolume(ByRef 文章作为变体)
Dim sorted As Boolean
Dim i As Integer
sorted = False
Do While Not sorted
sorted = True
For i = 0 To UBound(articles) - 1
If articles(i).volume < articles(i + 1).volume Then
Set temp = articles(i + 1)
Set articles(i + 1) = articles(i)
Set articles(i) = temp
sorted = False
End If
Next i
Loop
结束子
Sub SortArticlesBylenght(ByRef 文章作为变体)
Dim sorted As Boolean
Dim i As Integer
sorted = False
Do While Not sorted
sorted = True
For i = 0 To UBound(articles) - 1
If articles(i).lenght < articles(i + 1).lenght Then
Set temp = articles(i + 1)
Set articles(i + 1) = articles(i)
Set articles(i) = temp
sorted = False
End If
Next i
Loop
结束子