1. ## 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. ## 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. ## Re: Character Field Sorting

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. ## 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. ## 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. ## Re: Character Field Sorting

Hi John,

I must be missing something.
This will let us see what you're seeing.

7. ## 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.**

8. ## 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. ## Re: Character Field Sorting

confirmed.PNG

10. ## 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. ## 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.

12. ## Re: Character Field Sorting

Hey John,

Sorry I was out for a couple of days.

Originally Posted by hov333
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.

13. ## 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. ## 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")`

#### Posting Permissions

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