Edited by TroyWells on 09-Dec-01 19:08.
I’ve added “MY ATTEMPT” below with the associate problems.
I’ve read a lot about sorting arrays, but it still seems to be no easy feet. Thus, I need help sorting an array 3 times.
The array is 2 dimensional and is named/dimensioned as follows:
(Option Base 1)
ListFormatArray(8,ArrayColumnNumber)
I want to sort in ascending order the values in the second demension
1) by the 7th element in the first dimension
2) within those groupings by the 8th element of the first dimension
3) within those groupings by the 3rd element of the first dimension
I’ve looked at SortArray, but it seems to not be able to sort within a group easily.
An example of the order I hope to achieve is:
Order:
Numbers
No Table
Low Indent
High Indent
NonBordered Table
Low Indent
High Indent
Bordered Table
Low Indent
High Indent
Bullets
No Table
Low Indent
High Indent
NonBordered Table
Low Indent
High Indent
Bordered Table
Low Indent
High Indent
MY ATTEMPT**********************************************************************************
‘I included this section of values for testing purposes only.
ReDim Preserve ListFormatArray(8, 12) As Variant
ListFormatArray(1, 1) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 1) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 1) = “18” ‘ExistingParagraphIndent
ListFormatArray(4, 1) = ” Bordered” ‘Table Format
ListFormatArray(5, 1) = “” ‘ComboBox1 value
ListFormatArray(6, 1) = “” ‘ComboBox2 value
ListFormatArray(7, 1) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 1) = “0” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 2) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 2) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 2) = “36” ‘ExistingParagraphIndent
ListFormatArray(4, 2) = ” Bordered” ‘Table Format
ListFormatArray(5, 2) = “” ‘ComboBox1 value
ListFormatArray(6, 2) = “” ‘ComboBox2 value
ListFormatArray(7, 2) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 2) = “0” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 3) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 3) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 3) = “18” ‘ExistingParagraphIndent
ListFormatArray(4, 3) = ” Bordered” ‘Table Format
ListFormatArray(5, 3) = “” ‘ComboBox1 value
ListFormatArray(6, 3) = “” ‘ComboBox2 value
ListFormatArray(7, 3) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 3) = “0” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 4) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 4) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 4) = “36” ‘ExistingParagraphIndent
ListFormatArray(4, 4) = ” Bordered” ‘Table Format
ListFormatArray(5, 4) = “” ‘ComboBox1 value
ListFormatArray(6, 4) = “” ‘ComboBox2 value
ListFormatArray(7, 4) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 4) = “0” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 5) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 5) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 5) = “18” ‘ExistingParagraphIndent
ListFormatArray(4, 5) = ” Bordered” ‘Table Format
ListFormatArray(5, 5) = “” ‘ComboBox1 value
ListFormatArray(6, 5) = “” ‘ComboBox2 value
ListFormatArray(7, 5) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 5) = “0” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 6) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 6) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 6) = “36” ‘ExistingParagraphIndent
ListFormatArray(4, 6) = ” Bordered” ‘Table Format
ListFormatArray(5, 6) = “” ‘ComboBox1 value
ListFormatArray(6, 6) = “” ‘ComboBox2 value
ListFormatArray(7, 6) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 6) = “1” ‘0 for numbers and 1 for bullets
‘bullets
ListFormatArray(1, 7) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 7) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 7) = “18” ‘ExistingParagraphIndent
ListFormatArray(4, 7) = ” Bordered” ‘Table Format
ListFormatArray(5, 7) = “” ‘ComboBox1 value
ListFormatArray(6, 7) = “” ‘ComboBox2 value
ListFormatArray(7, 7) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 7) = “0” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 8) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 8) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 8) = “36” ‘ExistingParagraphIndent
ListFormatArray(4, 8) = ” Bordered” ‘Table Format
ListFormatArray(5, 8) = “” ‘ComboBox1 value
ListFormatArray(6, 8) = “” ‘ComboBox2 value
ListFormatArray(7, 8) = “0” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 8) = “1” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 9) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 9) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 9) = “18” ‘ExistingParagraphIndent
ListFormatArray(4, 9) = ” Bordered” ‘Table Format
ListFormatArray(5, 9) = “” ‘ComboBox1 value
ListFormatArray(6, 9) = “” ‘ComboBox2 value
ListFormatArray(7, 9) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 9) = “1” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 10) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 10) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 10) = “36” ‘ExistingParagraphIndent
ListFormatArray(4, 10) = ” Bordered” ‘Table Format
ListFormatArray(5, 10) = “” ‘ComboBox1 value
ListFormatArray(6, 10) = “” ‘ComboBox2 value
ListFormatArray(7, 10) = “1” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 10) = “1” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 11) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 11) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 11) = “18” ‘ExistingParagraphIndent
ListFormatArray(4, 11) = ” Bordered” ‘Table Format
ListFormatArray(5, 11) = “” ‘ComboBox1 value
ListFormatArray(6, 11) = “” ‘ComboBox2 value
ListFormatArray(7, 11) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 11) = “1” ‘0 for numbers and 1 for bullets
ListFormatArray(1, 12) = “0” ‘ExistingNumberStyle 0 through 4
ListFormatArray(2, 12) = “%5)” ‘ExistingNumberFormat
ListFormatArray(3, 12) = “36” ‘ExistingParagraphIndent
ListFormatArray(4, 12) = ” Bordered” ‘Table Format
ListFormatArray(5, 12) = “” ‘ComboBox1 value
ListFormatArray(6, 12) = “” ‘ComboBox2 value
ListFormatArray(7, 12) = “2” ‘Sort number for table format 0 no 1 non 2 bordered
ListFormatArray(8, 12) = “1” ‘0 for numbers and 1 for bullets
‘Sort the array by numbers/bullets, then by table type, and then by indent level.
Dim NumberListCount As Integer
Dim TableNoCountNumber As Integer, TableBorderCountNumber As Integer, TableNoBorderCountNumber As Integer
Dim TableNoCountBullet As Integer, TableBorderCountBullet As Integer, TableNoBorderCountBullet As Integer
NumberListCount = 0
TableNoCountNumber = 0
TableBorderCountNumber = 0
TableNoBorderCountNumber = 0
TableNoCountBullet = 0
TableBorderCountBullet = 0
TableNoBorderCountBullet = 0
WordBasic.SortArray ListFormatArray(), 1, ArrayColumnNumber, 0, 8
For N = 1 To ArrayColumnNumber
If ListFormatArray(8, N) = 0 Then NumberListCount = NumberListCount + 1
Next N
WordBasic.SortArray ListFormatArray(), 1, NumberListCount, 1, 7
WordBasic.SortArray ListFormatArray(), NumberListCount + 1, ArrayColumnNumber, 1, 7
For N = 1 To ArrayColumnNumber
If ListFormatArray(8, N) = 0 And ListFormatArray(7, N) = 0 Then
TableNoCountNumber = TableNoCountNumber + 1
ElseIf ListFormatArray(8, N) = 0 And ListFormatArray(7, N) = 1 Then
TableNoBorderCountNumber = TableNoBorderCountNumber + 1
ElseIf ListFormatArray(8, N) = 0 And ListFormatArray(7, N) = 2 Then
TableBorderCountNumber = TableBorderCountNumber + 1
ElseIf ListFormatArray(8, N) = 1 And ListFormatArray(7, N) = 0 Then
TableNoCountBullet = TableNoCountBullet + 1
ElseIf ListFormatArray(8, N) = 1 And ListFormatArray(7, N) = 1 Then
TableNoBorderCountBullet = TableNoBorderCountBullet + 1
ElseIf ListFormatArray(8, N) = 1 And ListFormatArray(7, N) = 2 Then
TableBorderCountBullet = TableBorderCountBullet + 1
End If
Next N
WordBasic.SortArray ListFormatArray(), 1, TableNoCountNumber, 1, 3
WordBasic.SortArray ListFormatArray(), TableNoCountNumber + 1, TableNoCountNumber + TableNoBorderCountNumber, 1, 3
WordBasic.SortArray ListFormatArray(), TableNoCountNumber + TableNoBorderCountNumber + 1, TableNoCountNumber + TableNoBorderCountNumber + TableBorderCountNumber, 1, 3
WordBasic.SortArray ListFormatArray(), TableNoCountNumber + TableNoBorderCountNumber + TableBorderCountNumber + 1, TableNoCountNumber + TableNoBorderCountNumber + TableBorderCountNumber + TableNoCountBullet, 1, 3
WordBasic.SortArray ListFormatArray(), TableNoCountNumber + TableNoBorderCountNumber + TableBorderCountNumber + TableNoCountBullet + 1, TableNoCountNumber + TableNoBorderCountNumber + TableBorderCountNumber + TableNoCountBullet + TableNoBorderCountBullet, 1, 3
WordBasic.SortArray ListFormatArray(), TableNoCountNumber + TableNoBorderCountNumber + TableBorderCountNumber + TableNoCountBullet + TableNoBorderCountBullet + 1, TableNoCountNumber + TableNoBorderCountNumber + TableBorderCountNumber + TableNoCountBullet + TableNoBorderCountBullet + TableBorderCountBullet, 1, 3
MsgBox ListFormatArray(8, 1) & “, ” & ListFormatArray(7, 1) & “, ” & ListFormatArray(3, 1)
MsgBox ListFormatArray(8, 2) & “, ” & ListFormatArray(7, 2) & “, ” & ListFormatArray(3, 2)
MsgBox ListFormatArray(8, 3) & “, ” & ListFormatArray(7, 3) & “, ” & ListFormatArray(3, 3)
MsgBox ListFormatArray(8, 4) & “, ” & ListFormatArray(7, 4) & “, ” & ListFormatArray(3, 4)
MsgBox ListFormatArray(8, 5) & “, ” & ListFormatArray(7, 5) & “, ” & ListFormatArray(3, 5)
MsgBox ListFormatArray(8, 6) & “, ” & ListFormatArray(7, 6) & “, ” & ListFormatArray(3, 6)
MsgBox ListFormatArray(8, 7) & “, ” & ListFormatArray(7, 7) & “, ” & ListFormatArray(3, 7)
MsgBox ListFormatArray(8, 8) & “, ” & ListFormatArray(7, 8) & “, ” & ListFormatArray(3, 8)
MsgBox ListFormatArray(8, 9) & “, ” & ListFormatArray(7, 9) & “, ” & ListFormatArray(3, 9)
MsgBox ListFormatArray(8, 10) & “, ” & ListFormatArray(7, 10) & “, ” & ListFormatArray(3, 10)
MsgBox ListFormatArray(8, 11) & “, ” & ListFormatArray(7, 11) & “, ” & ListFormatArray(3, 11)
MsgBox ListFormatArray(8, 12) & “, ” & ListFormatArray(7, 12) & “, ” & ListFormatArray(3, 12)
What I found is that this doesn’t seem to sort at all. I noticed I was missing a parameter:
SortArray ArrayName[$]() [, Order] [, From] [, To] [, SortType] [, SortKey]
But when I tried to add it (the Order parameter), it get a Bad Parameter error.
Thanks for your help!!
Troy