In article <48a52ba04c.B21306@...>,
<B21306@...> wrote:
> > You would like to search that field by allowing the user to specify
> > strings such as "5M" for 5 months, "2Y/J" for 2 years/jars etc.
> >
> > For example, writing "> 5M" in the query form would search the file for
> > all records where the "age" was more than 5 months.
> So it is.
> A Example is search for all calf is > 6 months , or search for a cow <10
> years , or in my new Apps search for food in my ice refrigerator >
> 8months.
OK. I've been having a little think about this and I believe it will be
possible, though a bit tricky.
First of all, is it necessary to store an age field with the file? It is
directly dependant on another field (date_of_birth) so can be easily
calculated whenever you need it, and is out of date almost immediately, so
needs constant re-calculation to be relevant.
My own (VH) opinion, would be to ditch the "age" field, and calculate the
age on the fly whenever you need it. If you look at the S-Base2 Tutorial
manual on page 158, or at the entry for "print" command in the Reference,
you can use the "interval" format - /i - for -displaying- ages. So
assuming today is 16th April,
print (@date - @timefoy(@date)):/i
3M1w
which means 3 Months, 1 week. Note though that although this is very quick
and simple to implement, it isn't absolutely accurate, as it assumes all
months are of equal length (31 days in this case). Most of the time it's
not that critical, but if you really need accurate ages for display
purposes then use the function I sent you earlier.
Searching for "age" though, using aY bM cD in the search expression is a
bit more complex, whether or not you save an "age" field with the file.
First of all, we have to convert the "aY bM cD" into something S can use
to compare with. Previously, you mentioned that using a search expression
of "> 5M" would return values of "14D" as acceptable. That's because 14 is
greater than 5 - S has no idea that the letters M and D have any meaning
in this context and simply compares the numbers.
Secondly, to allow the user all of the flexibility of the current query
operators (contains, equals, more than, etc) it would be useful not to
meddle with that. What we need is for the user to input something like
age = 5M {or}
age is greater than 1Y {etc}
and for our custom function only to process the bits it needs to.
I have attached a function which will do this for you.
The instructions for using it are also in the attached file, as some of
the lines are quite long.
When you set up a query using SAM, you are provided with 2 extra entry
fields - one for the record number of the file being searched, the second
for an arbitrary expression which can be applied to all the records in
turn, to see if they match the expression. This second extra field is what
I'm using - the function proc age_query_convert converts whatever is
written in this final slot to something S-Base can work with. However, it
needs some cooperation from the user, as detailed in the instructions.
For now, until you are happy with it, I've simplified the process and
sacrificed absolute accuracy, allowing constant periods for years and
months. If you want to, these can be made more complex.
Let me know how it works. Be careful though - I haven't had a chance to
test it fully yet.
Regards,
--
Robin Hampshire
robin@...