sez "Tiemo Hollmann TB" <toolb...@kestner.de>: To: "LiveCode User Liste senden" <use-livecode@lists.runrev.com> > I have a list field of words and a correspondent array with the words of the > field as the keys plus some data per key. I can store the array in a file, > read it later from file and rebuild the list of words from the keys of the > array. Up to now, I had this list of words alphabetically sorted. So it was > easy, when reloading the array to sort the list always alphabetically to > refresh the visible list in the field. > > The user can also create a custom sequence of the words in the field by drag > and drop the lines in individual order. Now I am looking for a smart > approach to keep the same sort order in the correspondent array. I need the > custom sort order of the words in case I reload the array later from file to > get the same sequence of words as the user has sorted them, after extracting > the words from the array. The key of the array has to keep the words from > the list for accessing the data in the array. > > As far as I see it, I have to add an additional item to the array data, > storing the sort sequence of the keys, while the user creates his custom > sequence of the words in the list field and keeping this number always > synchronous to the line number of the fields list. So I could use this "sort > sequence number" from the array to rebuild the same sort of the words when > extracting the words from the array. > > Would this be the best approach to keep the sort sequence of the words > stored with the array, or do you see an easier more straight forward > approach to keep the array "synchronous sorted" which I don't see right now? Use the alphabetically-sorted word-list as the keys of an array.
-- MySortedList is a return-delimited list, one word per line, sorted alphabetically -- UserSortedWordList is the return-delimited list of words sorted into the user's preferred order put "" into WordArray repeat for each line LL in MySortedList put lineOffset (LL,UserSortedWordList) into WordArray[LL] next repeat I'm not entirely sure that lineOffset (or even wordOffset) are the right thing to do here; there's every danger of encountering a Scunthorpe problem, such as if "pen" and "open" are both words in the list, or "squire" and "ire", etc etc. Hmm… maybe go with comma-delimited lists, and something along the lines of "put wordOffset (comma & LL & comma, comma & UserSortedWordList & comma) into WordArray[LL]" ? If this is what Mike Bonner had in mind, chalk it up to my inability to comprehend what he wrote. "Bewitched" + "Charlie's Angels" - Charlie = "At Arm's Length" Read the webcomic at [ http://www.atarmslength.net ]! If you like "At Arm's Length", support it at [ http://www.patreon.com/DarkwingDude ]. _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode