Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HELP.. Alpha Numeric sorting routines

Posted on 1997-10-27
8
Medium Priority
?
288 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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

885 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