Alpha Video Training
Results 1 to 14 of 14

Thread: Character Field Sorting

  1. #1
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    328

    Default Character Field Sorting

    Hi all,

    I'm trying to sort a character field that is used as a drop-down lookup.
    This field holds part numbers and does sometimes contain letters.

    Here is the current result of the lookup list:
    11111
    22222
    33333-3
    33333-4
    33333

    This is the desired result:
    11111
    22222
    33333
    33333-3
    33333-4

    Is there a character function to help achieve this sorting?
    Thanks!

  2. #2
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,389

    Default Re: Character Field Sorting

    Based on the data provided, I would be tempted to setup a "sort" column, based on the lookup column.
    I would replace the "-" with a period, then sort by val(sort)

  3. #3
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Character Field Sorting

    try loading the values into an array, then sort the array?

    This was obviously just using some text data elements, but you could initialize the array from a table as well.

    Code:
    DIM TXT[6] AS c
    TXT.initialize(<<%list% 
    11111
    22222
    33333-3
    33333-4
    33333
    %list%)
    txt.sort("A")
    results:sorted array.jpg

    Tom

  4. #4
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    328

    Default Re: Character Field Sorting

    thanks for the replies.
    Gregg I gave your's a shot first and although it seems like it should work, it works only partially.
    Here's what I put in the Display Order box in the lookup tab:
    sorting.JPG


    VAL(STRTRAN(PART_NUMBER,"-","."))
    Confirmed that the result is as follows: VAL(STRTRAN("11-2","-",".")) comes out to 11.2

    I then tested it as an equation: VAL(STRTRAN("11-2","-",".")) > VAL(STRTRAN("11","-",".")) the result yields True
    Opening the drop-down, it does sort in the correct order, HOWEVER, when typing "11" in the field it brings up the "11-2" number first even-though its listed as the second item...am I missing something?

  5. #5
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Character Field Sorting

    John,

    I'm sorry. I thought you were building an x-dialog box for the lookup. Let me go a little further and see what I can come up with.

  6. #6
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,389

    Default Re: Character Field Sorting

    Hi John,

    I must be missing something.
    Please consider sharing your component along with some sample data.
    This will let us see what you're seeing.

  7. #7
    Member
    Real Name
    Andrew Davidowicz
    Join Date
    Aug 2018
    Location
    New Jersey
    Posts
    23

    Default Re: Character Field Sorting

    Hey John,

    Hopefully I understand what you are going for. This seemed to work for me with limited knowledge of your table:
    Code:
    Padr(Numbers,7,"-0")
    Table with numbers:
    data table.PNG

    The Lookup:
    lookup.PNG

    Result:
    Result.PNG

    **EDIT: It should be padr, not padl... It somehow still worked with padl, but we need to add the "-0" to the right of the string.**
    Last edited by Davidowicza; 09-27-2019 at 01:07 PM. Reason: Syntax

  8. #8
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    328

    Default Re: Character Field Sorting

    Thanks Andrew, I'll give it a try later.
    Could you do me a favor and check also when typing in for example: "33" what is the suggestion that it brings up?
    The problem i was having was that the list was sorted correctly but it was suggesting the "-3" rather than "no dash" as the first entry.

  9. #9
    Member
    Real Name
    Andrew Davidowicz
    Join Date
    Aug 2018
    Location
    New Jersey
    Posts
    23

    Default Re: Character Field Sorting

    Confirmed (with the correct Padr())

    confirmed.PNG

  10. #10
    Member
    Real Name
    John P.
    Join Date
    Nov 2010
    Location
    Boston, MA
    Posts
    328

    Default Re: Character Field Sorting

    my part numbers are varying lengths so I tried including the len() function.
    It wasn't successful padr(PART_NUMBER,len(PART_NUMBER),"-0") did not even sort correctly. How would the padding function help to sort properly, I'm failing to understand the logic behind this.

  11. #11
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,698

    Default Re: Character Field Sorting

    Since your numbers do not have the save format, by adding the -0 to numbers that don't have that format makes the numbers consistent enough to sort them correctly.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  12. #12
    Member
    Real Name
    Andrew Davidowicz
    Join Date
    Aug 2018
    Location
    New Jersey
    Posts
    23

    Default Re: Character Field Sorting

    Hey John,

    Sorry I was out for a couple of days.

    Quote Originally Posted by hov333 View Post
    my part numbers are varying lengths so I tried including the len() function.
    It wasn't successful padr(PART_NUMBER,len(PART_NUMBER),"-0") did not even sort correctly. How would the padding function help to sort properly, I'm failing to understand the logic behind this.
    Does that mean my ordering filter is not working for you? With the information you provided, it will work. You showed us that your table has numbers with a length of 5 or 7, so that is why we padr() with a length of 7 on them, which would add the "-0" to all the 5 length numbers making them a length of 7 while putting them as the smallest for the group (11111-0) so alpha can sort them accordingly. Can you please be more specific on what you mean by "varying lengths"? Maybe that is where I am losing you.
    Last edited by Davidowicza; 10-01-2019 at 09:49 AM.

  13. #13
    Member
    Real Name
    Lonnie D Kelley
    Join Date
    Dec 2005
    Posts
    9

    Default Re: Character Field Sorting

    Just taking a guess here, but by varying lengths, we might see:
    A) the number to the right of the hyphen may increment above 9
    B) 33333-XXX (as he mentions that it sometimes contains letters)

  14. #14
    Member
    Real Name
    Andrew Davidowicz
    Join Date
    Aug 2018
    Location
    New Jersey
    Posts
    23

    Default Re: Character Field Sorting

    You are right Lonnie, I did miss that it sometimes includes letters...

    But taking a stab at what you are saying about the right of the hyphen, I'll go for the max length of each is XXXXX-XXXXX (Again assuming since we don't have that info.)

    This should work:

    Code:
    padl(word(Numbers,1,"-"),5,"0")+" "+padr(word(Numbers,2,"-"),5,"0")

Similar Threads

  1. sorting a character type field
    By noviceuser in forum Alpha Five Version 11 - Desktop Applications
    Replies: 12
    Last Post: 03-29-2013, 01:15 AM
  2. 1/2 character cut off at beginning of character field
    By Chris Spinney in forum Alpha Five Version 10 - Desktop Applications
    Replies: 7
    Last Post: 01-16-2013, 07:26 PM
  3. Sorting a mixed character field
    By scs010484 in forum Alpha Five Version 5
    Replies: 2
    Last Post: 08-05-2011, 09:39 AM
  4. sorting a character field
    By jbcc in forum Alpha Five Version 5
    Replies: 6
    Last Post: 04-04-2004, 01:25 PM
  5. Sorting Numbers in Character Field
    By JayMoskovitz in forum Alpha Five Version 5
    Replies: 4
    Last Post: 11-17-2003, 02:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •