- 积分
- 4434
- 明经币
- 个
- 注册时间
- 2006-7-11
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
正在做批打,需要双列条件排序,在网上没找到,自己写了一个。有需要的自己看吧- Function Sort(ByVal Data(,) As Double, ByVal List1 As Integer, ByVal Way1 As Integer, ByVal List2 As Integer, ByVal Way2 As Integer) As Object
- 'list1为主排序列,way1为主列排序方式(0为升序,非0为降序);list2为次排序列,way2为次列排序方式(0为升序,非0为降序)
- Dim i As Integer
- Dim j As Integer
- Dim temp As Double
- Dim ind As Integer
- Dim index() As Integer
- Dim zuobiao() As Double
- Dim list(,) As Double
- ReDim index(UBound(Data, 1))
- ReDim zuobiao(UBound(Data, 1))
- ReDim list(UBound(Data, 1), UBound(Data, 2))
- MsgBox(UBound(Data, 1))
- For i = 0 To UBound(Data, 1) - 1
- index(i) = i
- zuobiao(i) = Data(i, List1 - 1)
- Next
- '主列排序
- i = 0
- Do While i < UBound(Data, 1) - 1
- For j = i + 1 To UBound(Data, 1) - 1
- If Way1 = 0 Then
- If zuobiao(i) > zuobiao(j) Then
- temp = zuobiao(j)
- zuobiao(j) = zuobiao(i)
- zuobiao(i) = temp
- ind = index(j)
- index(j) = index(i)
- index(i) = ind
- End If
- Else
- If zuobiao(i) < zuobiao(j) Then
- temp = zuobiao(j)
- zuobiao(j) = zuobiao(i)
- zuobiao(i) = temp
- ind = index(j)
- index(j) = index(i)
- index(i) = ind
- End If
- End If
- Next
- i += 1
- Loop
- '次列排序
- For i = 0 To UBound(Data, 1) - 1
- list(i, 0) = Data(index(i), 0)
- list(i, 1) = Data(index(i), 1)
- list(i, 2) = Data(index(i), 2)
- list(i, 3) = Data(index(i), 3)
- index(i) = i
- zuobiao(i) = list(i, List2 - 1)
- Next
- i = 0
- Dim kg As Boolean = True
- Do While i < UBound(Data, 1) - 1
- If list(i, List1 - 1) = list(i + 1, List1 - 1) And kg = True Then
- j = i
- kg = False
- ElseIf list(i, List1 - 1) <> list(i + 1, List1 - 1) And kg = False Then
- Do While j < i
- For n As Integer = j + 1 To i
- If Way2 = 0 Then
- If zuobiao(j) > zuobiao(n) Then
- temp = zuobiao(j)
- zuobiao(j) = zuobiao(n)
- zuobiao(n) = temp
- ind = index(j)
- index(j) = index(n)
- index(n) = ind
- End If
- Else
- If zuobiao(j) < zuobiao(n) Then
- temp = zuobiao(j)
- zuobiao(j) = zuobiao(n)
- zuobiao(n) = temp
- ind = index(j)
- index(j) = index(n)
- index(n) = ind
- End If
- End If
- Next
- j += 1
- Loop
- kg = True
- End If
- i += 1
- Loop
- For i = 0 To UBound(Data, 1) - 1
- Data(i, 0) = list(index(i), 0)
- Data(i, 1) = list(index(i), 1)
- Data(i, 2) = list(index(i), 2)
- Data(i, 3) = list(index(i), 3)
- Next
- Sort = Data
- End Function
|
评分
-
查看全部评分
|