Skip to content

Commit 448f503

Browse files
committed
Export as sorted list
1 parent 060cd2a commit 448f503

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

source/modules/DeclarationDict.cls

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,23 +556,31 @@ Public Function LoadFromFile(ByVal FullFileName As String, Optional ByRef ErrorM
556556

557557
End Function
558558

559-
Public Sub ExportToFile(ByVal FullFileName As String)
559+
Public Sub ExportToFile(ByVal FullFileName As String, Optional ByVal ExportAsSortedList As Boolean = True)
560560

561+
Dim WordArray() As Variant
561562
Dim i As Long
562563

564+
WordArray = m_Words.Keys
565+
566+
If ExportAsSortedList Then
567+
QuickSort WordArray, LBound(WordArray), UBound(WordArray)
568+
End If
569+
563570
With New ADODB.Stream
564571
.Type = 2
565572
.Charset = "utf-8"
566573
.Open
567-
For i = 0 To m_Words.Count - 1
568-
.WriteText m_Words.Keys(i), adWriteLine
574+
For i = LBound(WordArray) To UBound(WordArray)
575+
.WriteText WordArray(i), adWriteLine
569576
Next
570577
.SaveToFile FullFileName, adSaveCreateOverWrite
571578
.Close
572579
End With
573580

574581
End Sub
575582

583+
576584
#If DebugPrintEnabled Then
577585

578586
Private Sub DebugPrint(ByVal Text2Output As String, _

source/modules/modSort.bas

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Attribute VB_Name = "modSort"
2+
Option Compare Database
3+
Option Explicit
4+
5+
Public Sub QuickSort(ByRef ArrToSort As Variant, ByVal FirstIndex As Long, ByVal LastIndex As Long)
6+
7+
Dim Low As Long, High As Long
8+
Dim Pivot As Variant, Temp As Variant
9+
10+
Low = FirstIndex
11+
High = LastIndex
12+
Pivot = ArrToSort((FirstIndex + LastIndex) \ 2)
13+
14+
Do While Low <= High
15+
Do While ArrToSort(Low) < Pivot
16+
Low = Low + 1
17+
Loop
18+
Do While ArrToSort(High) > Pivot
19+
High = High - 1
20+
Loop
21+
If Low <= High Then
22+
Temp = ArrToSort(Low)
23+
ArrToSort(Low) = ArrToSort(High)
24+
ArrToSort(High) = Temp
25+
Low = Low + 1
26+
High = High - 1
27+
End If
28+
Loop
29+
30+
If FirstIndex < High Then QuickSort ArrToSort, FirstIndex, High
31+
If Low < LastIndex Then QuickSort ArrToSort, Low, LastIndex
32+
33+
End Sub

0 commit comments

Comments
 (0)