Something Else I've Forgotten

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Something Else I've Forgotten

Post by RossG » Mon Nov 23, 2015 2:12 am

I want to sort numbers:

2,13,3,32...etc.

I can remember the second part...

if char(1) of x = 0 then
delete char(1) of x

but the first part, putting the zero before the
single digit numbers escapes me and I can't
find the appropriate thing in the dictionary.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Something Else I've Forgotten

Post by Dixie » Mon Nov 23, 2015 3:52 am

Don't know if I understand what you really want to do... but to put noughts in front of single numbers

Code: Select all

on mouseUp
   repeat with count = 1 to the number of lines of fld 1
      if the number of chars of line count of fld 1 = 1 then
         put 0 & line count of fld 1 into line count of fld 1
      end if
   end repeat
end mouseUp

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Something Else I've Forgotten

Post by dunbarx » Mon Nov 23, 2015 4:36 am

I am with Dixie.

You asked about sorting, and then asked about prepending a "0' to single digit numbers. If those two points are related, know that LC will sort "03" with the same rank as "3". That is, if either precedes the other in a list, and you sort numeric, those two elements will retain their positions.

Prepending a "0" may have other uses, if, say, it is desired that all the elements have the same length, for whatever reason.

But please tell us again what you are asking...

Craig Newman

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Something Else I've Forgotten

Post by RossG » Mon Nov 23, 2015 5:07 am

Yes, you're right but perhaps it wasn't always so?

My mistake was in coding it as

"sort the items of field x ascending"

rather than simply

"sort field x ascending numeric"

Thanks for your help.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Something Else I've Forgotten

Post by dunbarx » Mon Nov 23, 2015 3:41 pm

This behavior has been since the beginning. If you have:

1
01
1
01

If you sort this, you will get all the "01" listed first. This is because a normal sort uses ASCII values, and "0" precedes "1". But if you sort numeric, well, you know what happens.

Craig

Post Reply