Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!gdavis From: gdavis@primate.wisc.edu (Gary Davis) Newsgroups: comp.sys.mac.hypercard Subject: Re: Complex sorting in Supercard 1.5 Message-ID: <4535@uakari.primate.wisc.edu> Date: 19 Jun 91 04:40:45 GMT References: Sender: news@primate.wisc.edu Reply-To: gdavis@primate.wisc.edu Lines: 32 From article , by mg2x+@andrew.cmu.edu (Michael Andrew Gelman): > I'm working in SuperCard, but I think that HyperCard works the same way > (at least the older HyperCard). I could be wrong, though, but I'll take > any clue. > > I've got this stack that has four fields on it, F1...F4. I need the > stack sorted by all the fields, that is first by F1, then by F2, etc. > > Here's the trick. F3 and F4 are sometimes text and sometimes numeric. > If I do something like: > > sort by F1 & F2 & F3 & F4 > > I end up with the card that has F3 = "10" next to the card that has F3 = > "1". It appears to be sorting by character, left to right. Which is > right for text, but wrong for numbers. > I can't just sort numeric, because that doesn't do anything with text fields. > Has anyone run across this? Can anyone see a solution? One way this could be done in HyperCard, and perhaps in SuperCard, would be to take advantage of the fact the HC can sort on any arbitrary expression. So, instead of sorting by F3, you could sort by a function of F3. The function could look at the field's value and if it were alphabetic, just return the value. If it were numeric, then the function could calculate some appropriate set of characters which would place the card in numeric order. If you want cards with numbers to come before cards with text, then the function might return "aaa" & n for n < 10, "aab" & n for 9 < n < 100 and so forth. (Oops, might need another "a", if aardvark is in your text.) Other characters could be used if you know where HC sorts them. Gary Davis