Solved

HELP.. Alpha Numeric sorting routines

Posted on 1997-10-27
8
282 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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 200 total points
ID: 1348927
See comments for answer...
JB
0
 

Author Comment

by:westy100697
ID: 1348928
Thanks again JB
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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 …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

733 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