Subject Re: Another problem (non-grid)
From Mervyn Bick <invalid@invalid.invalid>
Date Sun, 17 Dec 2017 08:24:23 +0200
Newsgroups dbase.getting-started

On 2017-12-17 12:40 AM, Charlie wrote:
> Thanks for the help on the grid problem.
>
> OK now I am wondering how someone would program this.  Should be pretty easy but I was on the golf course today and am to golfed out to think!
>
> So I have a character field.  I am organizing it now so it will look presentable.  I have been using 1,2,3,...12 and now I want to show this in a logical order.  So I would like all characters to look something like 001, 002, 003,...012 so they make a more logical order.
>
> I have many records that are of the first example.  Would there be an easy loop to fix them to resemble the second example?
>
> Thanks again!!!!   Happy holidays everyone!
>

use yourtable exclusive
replace all yourfield with right('000'+trim(yourfield),3)
index on yourfield tag num_order
use

This will take care of values up to '999' and will give you

...
008
009
010
011
...
100
101

You could also use

use yourtable exclusive
replace all yourfield with right(space(3)+trim(yourfield),3)
index on yourfield tag num_order
use

This will give you
...
   8
   9
  10
  11
...
100
101

Any new values added to the table must be entered with either the
leading zeros or the leading spaces.


As an alternative you can leave the contents as they are and create an
index which will present the value in the correct order.  They will,
however be presented left justified.

use yourtable exclusive
index on right(space(3)+trim(yourfield),3) tag num_order
use

This will give you
...
8
9
10
11
...
100
101

In this case any new values would be entered without the leading spaces
as the index will take care of this.

Once you have created the index by using one of the methods above when
you need yourfield in proper numerical order simply

use yourtable order num_order



Mervyn.