PDA

View Full Version : [SOLVED:] Sorting an array of delimited strings



Jfp87
03-10-2017, 06:41 AM
Guys,

I am looking for some advice regarding the following problem. I think I might be over complicating it.

I have an array where each element is a delimited string. Each delimited string holds data associated with a Content Control in the ActiveDocument, e.g.

arrCCData(1) = 2|21|CC2 in textbox 1|16
arrCCData(2) = 1|56|Current Project Cost in Pounds|30
arrCCData(3) = 1|113|Completion Date|15
arrCCData(4) = 1|32|Contractor|10
arrCCData(5) = 1|371|Video|5
arrCCData(6) = 2|1|CC1 in textbox 1|16
arrCCData(7) = 0|1|ClientSurveyNumber|18
arrCCData(8) = 1|399|way|3
arrCCData(9) = 1|527|You can also|12
arrCCData(10) = 1|5|Client|6
arrCCData(11) = 0|1|Footer CC|9
arrCCData(12) = 0|22|SurveyDate|10


I am trying to sort the array by token 1 of each element to achieve:

0|1|ClientSurveyNumber|18
0|1|Footer CC|9
0|22|SurveyDate|10
1|5|Client|6
1|32|Contractor|10
1|56|Current Project Cost in Pounds|30
1|113|Completion Date|15
1|371|Video|5
1|399|way|3
1|527|You can also|12
2|1|CC1 in textbox 1|16
2|21|CC2 in textbox 1|16


Then finally by token 2 to achieve the final result:

0|1|ClientSurveyNumber|18
0|1|Footer CC|9
0|22|SurveyDate|10
1|5|Client|6
1|32|Contractor|10
1|56|Current Project Cost in Pounds|30
1|113|Completion Date|15
1|371|Video|5
1|399|way|3
1|527|You can also|12
2|1|CC1 in textbox 1|16
2|21|CC2 in textbox 1|16

What is the easiest way to do this?

I am currently using a customized quicksort procedure to sort the array by token 2 of each element. I am then looping through the partially sorted array and copying the elements into a separate array. The position in the new array is based on token 1.

It's easier to explain by example. Any advice on the best way to do this would be appreciated. See attached.

Joe

gmaxey
03-10-2017, 11:31 AM
Hi Joe,

I would probably do this with a userform (never shown) and a ListBox sort function.

See attached file.

gmaxey
03-10-2017, 11:37 AM
Joe,

Modify that code as follows. I had taken the line out and now realizes it needs to be there:


With oFRm
.ListBox1.List = arrCCData
.ListBox1.ColumnCount = 4 'Add this line.

Jfp87
03-12-2017, 12:12 PM
Greg, thanks. I will have a look at this tomorrow but I hadn't even thought of using a listbox control to solve that problem. I suppose it may be better using built-in functionality where possible. I have no idea what approach will be faster for large amounts of data - maybe that is a test I could do.

Joe