[comp.databases] dbase-iii or foxbase-plus

mdf@tut.cis.ohio-state.edu (Mark D. Freeman) (02/25/88)

In <171@wsccs.UUCP> bill@wsccs.UUCP (Bill Housley) writes:
>In article <2658@orstcs.CS.ORST.EDU>, nacer@mist.cs.orst.edu (Abdenacer Moussaoui C.) writes:
>> I am trying to create an index but in the reverse (descending) order:
>> 
>>  		INDEX ON - FLD TO <FILE>
>> 
>> will work if the field is numeric but, what if the field is in a date format?
>
>The STR() function will return "02/22/88" or whatever, you will want to
>do some further processing on it first to get something like "19880222"
>(Clipper of Fall '86 automaticaly does this from a date format with the
>DTOS() function).

Foxplus 2.0 has a dtoc(datefield, 1) function.  The send parameter
tells it to do what Clipper's dtos() does.

>Here is a source code example for Dbase II or III:
>procedure dtos
>parameters dt, dtstr
>
>store substr(dt,1,2) to temp2   	
>store substr(dt,4,2) to temp3
>store substr(dt,7,1) to temp1
>
>store "19"+temp1+temp2+temp3 to dtstr
>return 

Try this for slightly better performance:

PROCEDURE dtos
PARAMETERS dt, dtstr

dtstr = substr(dt,7,2) + substr(dt,4,2) + left(dt, 2)

RETURN

>you might be able to make it into a
>user-defined function since I don't remember if that is a Dbase or
>Clipper option.  

Foxbase will allow user defined functions as well as Clipper, but they
are not needed for this case.  The main advantage of user-defined
functions is that you can return a value instead of having to pass it
through intermediate variables (dtstr in the example).  So, in order to
use the above PROCEDURE, you'll need to store an extra field in the
file, and index on that.  The new field will contain the date as
processed by the dtos PROCEDURE.  If you have user defined functions,
you could just say INDEX ON dtos(dt) TO foo.




-- 
Mark D. Freeman						  (614) 262-1418
					      mdf@tut.cis.ohio-state.edu
2440 Medary Avenue	   ...!cbosgd!osu-cis!tut.cis.ohio-state.edu!mdf
Columbus, OH  43202-3014      Guest account at The Ohio State University