-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmodListViewSort.bas
115 lines (102 loc) · 3.97 KB
/
modListViewSort.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Attribute VB_Name = "modListViewSort"
Option Explicit
Public Sub ListViewSort(ByRef lListView As ListView, ByRef ColumnHeader As MSComctlLib.ColumnHeader, ByRef iSortOrder As Integer)
Dim l As Long
Dim sFormat As String
Dim sData() As String
Dim lIndex As Long
On Error Resume Next
With lListView
lIndex = ColumnHeader.Index - 1
Select Case LCase$(ColumnHeader.Tag)
Case "number"
sFormat = String(30, "0") & "." & String(30, "0")
With .ListItems
If (lIndex > 0) Then
For l = 1 To .Count
With .Item(l).ListSubItems(lIndex)
.Tag = .Text & ChrW$(0) & .Tag
If IsNumeric(.Text) Then
If CDbl(.Text) >= 0 Then
.Text = Format(CDbl(.Text), _
sFormat)
Else
.Text = "&" & InvNumber( _
Format(0 - CDbl(.Text), _
sFormat))
End If
Else
.Text = ""
End If
End With
Next l
Else
For l = 1 To .Count
With .Item(l)
.Tag = .Text & ChrW$(0) & .Tag
If IsNumeric(.Text) Then
If CDbl(.Text) >= 0 Then
.Text = Format(CDbl(.Text), _
sFormat)
Else
.Text = "&" & InvNumber( _
Format(0 - CDbl(.Text), _
sFormat))
End If
Else
.Text = ""
End If
End With
Next l
End If
End With
.SortOrder = iSortOrder
.SortKey = ColumnHeader.Index - 1
.Sorted = True
With .ListItems
If (lIndex > 0) Then
For l = 1 To .Count
With .Item(l).ListSubItems(lIndex)
sData = Split(.Tag, ChrW$(0))
.Text = sData(0)
.Tag = sData(1)
End With
Next l
Else
For l = 1 To .Count
With .Item(l)
sData = Split(.Tag, ChrW$(0))
.Text = sData(0)
.Tag = sData(1)
End With
Next l
End If
End With
Case Else
.SortOrder = iSortOrder
.SortKey = ColumnHeader.Index - 1
.Sorted = True
End Select
End With
End Sub
Private Function InvNumber(ByRef sNumber As String) As String
Dim i As Integer
Dim iNumberLength As Integer
iNumberLength = Len(sNumber)
For i = 1 To iNumberLength
Select Case Mid$(sNumber, i, 1)
Case "-": Mid$(sNumber, i, 1) = " "
Case "0": Mid$(sNumber, i, 1) = "9"
Case "1": Mid$(sNumber, i, 1) = "8"
Case "2": Mid$(sNumber, i, 1) = "7"
Case "3": Mid$(sNumber, i, 1) = "6"
Case "4": Mid$(sNumber, i, 1) = "5"
Case "5": Mid$(sNumber, i, 1) = "4"
Case "6": Mid$(sNumber, i, 1) = "3"
Case "7": Mid$(sNumber, i, 1) = "2"
Case "8": Mid$(sNumber, i, 1) = "1"
Case "9": Mid$(sNumber, i, 1) = "0"
End Select
Next
InvNumber = sNumber
End Function