1: Private col As Collection
2: Private WithEvents txt As TextBox
3: Private bEnabled As Boolean
4: Private bLastKeyDel As Boolean
5:
6: Public Property Get Enabled() As Boolean
7: Enabled = bEnabled
8: End Property
9:
10: Public Property Let Enabled(bNew As Boolean)
11: Debug.Assert bNew And Not (col Is Nothing)
12: Debug.Assert bNew And Not (txt Is Nothing)
13: bEnabled = bNew
14: End Property
15:
16: Public Property Get TextBox() As TextBox
17: Set TextBox = txt
18: End Property
19:
20: Public Property Set TextBox(txtNew As TextBox)
21: Set txt = txtNew
22: End Property
23:
24: Public Property Get Collection() As Collection
25: Set Collection = col
26: End Property
27:
28: Public Property Set Collection(colNew As Collection)
29: Set col = colNew
30: End Property
31:
32: Public Sub ResortCollection()
33: Debug.Assert Not (col Is Nothing)
34: If col.Count <= 1 Then Exit Sub
35: Dim i As Long
36: Dim j As Long
37: Dim nGap As Long
38: Dim bResult As Boolean
39: Dim tmp
40: Dim tmp2
41: nGap = col.Count / 2
42: Do While nGap > 0
43: For i = nGap To col.Count - 1
44: tmp = col(i + 1)
45: j = i
46: bResult = (StrComp(tmp, col(j - nGap + 1), vbBinaryCompare) = -1)
47: Do While j >= nGap And bResult
48: tmp2 = col(j - nGap + 1)
49: col.Remove j + 1
50: If j + 1 > col.Count Then
51: col.Add tmp2
52: Else
53: col.Add tmp2, , j + 1
54: End If
55: j = j - nGap
56: If j >= nGap Then
57: bResult = (StrComp(tmp, col(j - nGap + 1), vbBinaryCompare) = -1)
58: End If
59: Loop
60: col.Remove j + 1
61: If j + 1 > col.Count Then
62: col.Add tmp
63: Else
64: col.Add tmp, , j + 1
65: End If
66: Next
67: nGap = nGap / 2
68: Loop
69: End Sub
70:
71: Private Sub txt_Change()
72: If Not bEnabled Or bLastKeyDel Then
73: Exit Sub
74: End If
75: If txt.SelStart <> Len(txt.Text) Then
76: Exit Sub
77: End If
78: If txt.Text = "" Then
79: Exit Sub
80: End If
81: Dim vItem As Variant
82: Dim sContain As String
83: sContain = LCase(txt.Text)
84: For Each vItem In col
85: If Mid(LCase(vItem), 1, Len(sContain)) = sContain Then
86: txt = txt & Mid(vItem, Len(sContain) + 1)
87: txt.SelStart = Len(sContain)
88: txt.SelLength = Len(txt) - Len(sContain)
89: Exit For
90: End If
91: Next
92: End Sub
93:
94: Private Sub txt_KeyDown(KeyCode As Integer, Shift As Integer)
95: If Not bEnabled Then
96: Exit Sub
97: End If
98: If KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Then
99: bLastKeyDel = True
100: Else
101: bLastKeyDel = False
102: End If
103: End Sub