Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!stadler From: stadler@Apple.COM (Andy Stadler) Newsgroups: comp.sys.mac.hypercard Subject: sorting problems (was: Why?) Message-ID: <50903@apple.Apple.COM> Date: 27 Mar 91 22:17:03 GMT References: <120@lake.scar.toronto.edu> Distribution: na Organization: Apple Computer Inc., Cupertino, CA Lines: 46 In article <120@lake.scar.toronto.edu> barek@lake.scar.toronto.edu (William Barek) writes: > > Secondly, I could not belive that sorting is almost useless (please no > flames). Why. Have you ever tried to sort 2 fields ( one text, other > numeric) or lines in a field that have two columns one is text other is > numeric). To me it is a very basic operation, why this was missed or am > I missing something? Both of these tricks are easy. To sort using multiple keys, just sort the stack multiple times, starting with the minor sort key and finishing with the major sort key. For example, if you have a stack with first name and last name fields, you would sort it like this: sort by bkgnd field "first name" sort by bkgnd field "last name" HyperCard's sort is "stable" which means that if two keys are identical, the cards will never be swapped. This assures that multi-key sorts work correctly. To sort by particular elements of a field, just use "item n" to determine the location of the elements. In the previous example, suppose you have a single "name" field in which the names are entered as "lastname, firstname". You could sort it with these two commands: sort by item 2 of bkgnd field "name" -- sorts first names sort by item 1 of bkgnd field "name" -- now sort the last names You can use all kinds of selectors to specify your sort key. We call them "chunk expressions." A chunk can be chars, items, words, lines, or any combination of the above. To build really complex things, use a creation pass to go through the stack, extract exactly what you want, and put it in another field; then sort the stack using that field. But you almost never need to go this far, in practice. There are many other options in the sort command, such as sort style [text/ numeric/international] and sort direction [ascending/descending]. In addition you can sort only those cards meeting certain criteria [sort marked cards] and you can sort items within a container. I'm sorry you aren't happy with 2.0, but I suspect you haven't taken the time to really dig into its capabilities. It's really quite powerful! Andy Stadler HyperCard IIGS Team Apple Computer, Inc.