O
Omh
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">код</div></div><div class="sp-body"><div class="sp-content"><!--shcode--><pre><code class='ls'>Sub ArraySortSub(Array As Variant, SortOrder As Integer)
On Error Goto Errh
If Isempty(Array) Then Exit Sub
If Not Isarray(Array) Then Exit Sub
Dim done As Variant
Dim Jump As Long
Dim i As Long
Dim j As Long
Dim n As Long
Dim x As Long
Dim Temp As Variant
Dim Val_i As Variant
Dim Val_j As Variant
Dim Swap As Boolean
x = Lbound(Array)
n = Ubound(Array)
Jump = n
Do While Jump > 1
Jump = Jump \ 2
Do
done = True
For j = x To n - Jump
i = j + Jump
Val_i = Array(i)
Val_j = Array(j)
Select Case SortOrder
Case SORT_ASC: Swap = Val_j > Val_i
Case SORT_DSC: Swap = Val_j < Val_i
Case Else: Swap = Val_j > Val_i
End Select
If Swap Then
Temp = Array(i)
Array(i) = Array(j)
Array(j) = Temp
done = False
End If
Next
Loop Until done
Loop
Exit Sub
Errh:
Call ErrHandler
Exit Sub
End Sub[/CODE]
On Error Goto Errh
If Isempty(Array) Then Exit Sub
If Not Isarray(Array) Then Exit Sub
Dim done As Variant
Dim Jump As Long
Dim i As Long
Dim j As Long
Dim n As Long
Dim x As Long
Dim Temp As Variant
Dim Val_i As Variant
Dim Val_j As Variant
Dim Swap As Boolean
x = Lbound(Array)
n = Ubound(Array)
Jump = n
Do While Jump > 1
Jump = Jump \ 2
Do
done = True
For j = x To n - Jump
i = j + Jump
Val_i = Array(i)
Val_j = Array(j)
Select Case SortOrder
Case SORT_ASC: Swap = Val_j > Val_i
Case SORT_DSC: Swap = Val_j < Val_i
Case Else: Swap = Val_j > Val_i
End Select
If Swap Then
Temp = Array(i)
Array(i) = Array(j)
Array(j) = Temp
done = False
End If
Next
Loop Until done
Loop
Exit Sub
Errh:
Call ErrHandler
Exit Sub
End Sub[/CODE]