Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HELP.. Alpha Numeric sorting routines

Posted on 1997-10-27
8
Medium Priority
?
286 Views
Last Modified: 2013-11-24
If anyone has an Alphanumeric sorting routine that can be used for DBase tables would it be possible to post it up. This would be of great benefit to me and am willing to offer points for it. Make it 200 say.
                             Muchly appreciated WESTY  
0
Comment
Question by:westy100697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1348921
What kind of sorting are you looking for?  SQL?  Table indeces? General sorting routines in code (not only for DBase)?

JB
0
 

Author Comment

by:westy100697
ID: 1348922
I am looking mainly for a sort routine for Table indeces. But could also use one for normal sort routines in code that is also.
Don't know if you can help but if you can then thanks in Advance.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1348923
Hi

I'm still not 100% sure what you are looking for, but there are several ways to sort DBase data:

1) You can put an index on the field you want to sort by.  Do this in Database Desktop; open your table, choose Restructure on the Table menu, & then choose "Define" for the Indeces.

2) You can enter data into the table in any order, and extract it in the order you want.  This is done with a query.  E.g.  If you have a table called "Cust" with a field "CustName", you can put a TQuery component on a form, and in the SQL property type:

SELECT * FROM Cust ORDER BY CustName

(You will obviously have to give the TQuery a DatabaseName, and you may want to link it to a TDBGrid via a TDataSource.)

These are 2 common ways of sorting database data alphanumerically.

JB
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:westy100697
ID: 1348924
JB,
   The heart of my problem is this...I am adding records to a table that has several different indeces. Now with Aplhanumeric
fields or Character fields the data will not be ordered correctly. ie Numeric fields list 1,2,3,4,5,6,...etc
              Character fields list 1,10,11,12,13,14,15,16,17,
                                    18,19,2,20 or something like this.
Now i need to show the data in the correct order at all times so
and so i think doing it dynamically is the best way. It has to be an Alphanumeric field too as our clients have requested it. I guess i am wondering if it is possible to display an active table
that is indexed using an Alphanumeric field in the correct order all the time not just sort it once and thats it. Does that give you some light on the direction i am looking.
                                              WESTY    

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1348925
Hi

I see what you're aiming for now, and I'm afraid that with the limited SQL in DBase & Paradox you may struggle to get it right.  I once had a similar situation (i.e. a field with letters & numbers, and the value "2" must come before "11") and this is how I solved the problem.  (It is a little clumsy, and maybe there's a better way, but it worked for me...)

I created a dummy field, and in my table's OnBeforePost event I created the value for my dummy field.  E.g. My main field is called ALPHAMAIN and my dummy field is ALPHADUMMY.

In the OnBeforePost event I check the value of ALPHAMAIN.  If it is a number I insert zeroes in front to make its length 12 characters.  Thus 2 becomes 000000000002 and 12345 becomes 000000012345.  If it is not a number, I leave it.  This new value goes into ALPHADUMMY, and I have an index on ALPHADUMMY.

Here is the code for the above:

function IsNumeric(s: string): Boolean;
begin
    try
        StrToInt(s);
        Result := True;
    except
        Result := False;
    end;
end;

function Pad(ANum, NumLeadingZero: Integer): string;
begin
    Result := IntToStr(ANum);
    while (Length(Result) < NumLeadingZero) do
            Result := '0' + Result;
end;

procedure TForm1.Table1BeforePost(DataSet: TDataSet);
begin
    if (IsNumeric(Table1.FieldByName('AlphaMain').AsString)) then
        Table1.FieldByName('AlphaDummy').AsString := Pad(StrToInt(Table1.FieldByName('AlphaMain').AsString), 12)
    else
        Table1.FieldByName('AlphaDummy').AsString := Table1.FieldByName('AlphaMain').AsString;
end;

JB
0
 

Author Comment

by:westy100697
ID: 1348926
OK JB thats good direction and I thank you muchly. Hey you might want to lock the quetion so I can give you the points.
                                                Cheers Westy
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 800 total points
ID: 1348927
See comments for answer...
JB
0
 

Author Comment

by:westy100697
ID: 1348928
Thanks again JB
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question