Solved

HELP.. Alpha Numeric sorting routines

Posted on 1997-10-27
8
276 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
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:JimBob091197
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:westy100697
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:JimBob091197
Comment Utility
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
Comment Utility
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 200 total points
Comment Utility
See comments for answer...
JB
0
 

Author Comment

by:westy100697
Comment Utility
Thanks again JB
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Viewers will learn the different options available in the Backstage view in Excel 2013.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now