Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sort a Scripting.Dictionary? (Word 2002(10.2627.2625))

    i want to sort a scripting.dictionary object on the Items (the Keys are how it is sorted by nature). My initial thoughts about this suggest that i create a new document and a new table, pour the dictionary into the table, and use the Word sort procedure.

    Is this a reasonable approach?

    I expect to do a lot of this - what sort algorithm is used in Word? Quicksort? HeapSort? Bubblesort? Should i write my own?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Sort a Scripting.Dictionary? (Word 2002(10.2627.2625))

    > what sort algorithm is used in Word? Quicksort? HeapSort? Bubblesort?

    I don't know, but why should it matter? The rules for how data will sort (e.g., string, number, date, case sensitive) are configurable, so you should get the right result regardless of the algorithm. As for its efficiency, you'll have to test with real-world data.

    As an alternative, if your data elements are unique strings, how about something like this?

    <pseudocode>
    For Each key in Dictionary1.Items
    Dictionary2.Add Dictionary1.Item(key), Dictionary1.Key(key)
    Next
    </pseudocode>

    In theory, this will create a second dictionary in which the keys are the items from the first dictionary, and the items associated with those keys are the keys to the corresponding items in the first dictionary. Dictionary2 then will be "sorted" by the data from Dictionary1. Worth a shot? (While theoretically you could do this swap without creating a new dictionary, I suspect that the loop would not work correctly.)

  3. #3
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sort a Scripting.Dictionary? (Word 2002(10.2627.2625))

    It matters if the sort is slow. I wasnt clear when i said i was going to do a lot of this; what i meant was that there could be a large dictionary. [aside: it is interesting to note that i could find nothing in the KB naming the sort algorithm]

    Unfortunately, the data values arent unique, so the excellent 2-dictionary idea doesnt apply. <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Sort a Scripting.Dictionary? (Word 2002(10.2627.2625))

    Although Sort... is on the Table menu, it works perfectly well with paragraphs. It probably would run faster without the table overhead.

  5. #5
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    Faifax, Virginia, USA
    Posts
    542
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sort a Scripting.Dictionary? (Word 2002(10.2627.2625))

    good idea!

    I'll try it both ways, as that is the only way to be sure.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •