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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Sort a Scripting.Dictionary? (Word 2002(10.2627.2625))

    • This topic has 4 replies, 2 voices, and was last updated 23 years ago.
    Author
    Topic
    #368672

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #578505

      > 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?

      For Each key in Dictionary1.Items
      Dictionary2.Add Dictionary1.Item(key), Dictionary1.Key(key)
      Next

      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.)

      • #578506

        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. bummer

        • #578518

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

          • #578546

            good idea!

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

            Thanks!

    Viewing 0 reply threads
    Reply To: Sort a Scripting.Dictionary? (Word 2002(10.2627.2625))

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: