Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Sort Array AR2 error (I think)

Using 2.0.2.RC12

The order is not correct using the values in field 2.
They are all numeric, but different lengths, some with dec points.
Screen show shows before and after.
The before screen shot is actually in order in this case, but this is not guaranteed so I run it through the sort to be sure.


  • Worried... not sure if I have released this already.
  • Another example also trashes the table with Char(0)s
    Loads of things failing now.
  • This is working as designed. Just like OI's own V119 routine, a right-aligned sort is only good for sorting integers, since it doesn't actually compare true numerical values. A right-aligned sort effectively "inserts" spaces to the left of each value until everything is the same length before sorting them. If you look at your results and imagine spaces before your integers then you'll see what I mean.

    That being said, I realize some of our documentation uses the terms "numerical" when describing the sorting process, so I accept responsibility to setting up false expectations. As a mea culpa, I will update the sorting algorithms to treat N as a true numerical sort and R as a traditional right sort (for backward compatibility with V119). The sort will be slower since it will have to convert each value it sorts into a true decimal number while sorting and back to a string again.
  • edited October 2018
    Since I'll be updating code today, can you elaborate on things being trashed with Char(0)s?
  • Understand the right-aligned sort issue.
    I think as long as its documented and made clear then we can deal with it internally.
    It does mean a pre-process before any sort to ensure that all values are formatted with leading and trailing zeros.

    Having said that the N sort would be great , as it means no pre-processing.
  • Re trash with char (0), see screen shot, with code, and before and after files as TXT.

    T1.txt 24.7K
    T2.txt 24.7K
  • SRP Utilities 2.0.3 RC1 now supports true numerical sorting. Instead of using "AR2" for the sorting parameter, try "AN2" instead.
  • Have tested, AN sort works fine.
  • Are the Char(0)s still an issue though?
  • Have tested that as well, fixed at the same time, excellent.
  • The right-justified sorting in V119 appears to be quite complex. It can sort text strings that contain numbers, numerically by those numbers. This goes for decimals and negatives too.

    Eg, a V119 Right justified sort on these strings (comma delimted)
    a15.8 a-20y a15.3 a-15.8f a20 a-15.3 a-1.8 a-1.3x a0 a1.3 a1.8will result as
    a-20y a-15.8f a-15.3 a-1.8 a-1.3x a0 a1.3 a1.8 a15.3 a15.8 a20
    (Kevin - see our email discussions ~ July 8, 2010)

    Cheers, M@
  • I see. Right sort is actually extracting numbers and sorting accordingly. Interesting.
  • Ah, I see, looked at that and thought it was wrong, but now I see that the negative values are in fact used.
    Might not always be right, as the - character might be a delimiter of a field rather than a minus sign.

    I think any sorts that require this type of content needs to be addressed by the code.

Sign In or Register to comment.