Announcement

Collapse
No announcement yet.

Sorting udt array vs tagalong

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    not sure how it would behave if numeric's were part of the mix. Am I missing something?
    You are not missing anything if you are not sure what happens when some of the UDT members are numeric.

    Pure and simple, the sort will not work; what I posted works only on strings.

    When you have a mix of strings and numbers in your UDT, using the "CALL FunctionName()" option is the most straightforward way to accomplish a multi-key sort.

    There is another way, which I published in Basically Speaking magazine a number of years ago, but I was unable to find it last time I looked.. it uses the START and FOR options of the ARRAY SORT statement and is a lot more complicated than what it takes with the "custom sort callback function" option available since PB/Win 9x.

    I guess I can look again since I moved "everything" to the new computer...including all my old PB for MS-DOS code.

    Come to think of it, I think that macro might work for a single member sort, string or numeric.. lt me look now..nak, I was right, it won't work.

    But you know, by using the CALL FunctionName() option in that MACRO you could make it work. (Well, you could, but it would be silly to do so when you can do it 'directly' on your target Array).

    But related to your concern, it's why I developed the STRING SIGNED BINARY datatype... a numeric which sorts as a string. Demo here:

    String Signed Binary (SSB) Functions for PB-DOS (May 1997)



    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #22
      Originally posted by Michael Mattias View Post
      You are not missing anything if you are not sure what happens when some of the UDT members are numeric.
      Pure and simple, the sort will not work; what I posted works only on strings.
      Ah, yes. I was mistaken. ARRAY SORT using FROM...TO is intended only for string arrays. While it doesn't give an error, it doesn't sort numeric members correctly. (It still sorts string members of the array correctly)

      Comment

      Working...
      X