Finding a date on a list

Martin Luce martinluce at eclipse.co.uk
Mon Feb 15 10:44:52 UTC 2021


Hi Doug

I tried the various options from your email and what has worked for me, as the list is already sorted with latest date on line 1, is 

Do L_TransLst.$search($ref.c1<=i_DateEnd,kTrue,kFalse,kTrue,kTrue) Returns L_Line

c1 is column number which I find works instead of the column name when the column name is a file field name

I have also added 

Do List.$sort($ref.c1.0) and Do List.$sort($ref.c1.1) to my list of useful things

I found that I could not get your last suggestion to work

Many thanks

Martin

> On 14 Feb 2021, at 21:11, Doug Easterbrook <doug at artsman.com> wrote:
> 
> hi Martin.
> 
> If you are out to find the last line that matches the date
> 
> searchdate=’some date’
> 
> do list.$sort($ref.TranDate,1)    ## sort by date descending, although you could sort by ascending)
> do list.$search($ref.TranDate<=searchdate,ktrue,kfalse,ktrue,ktrue)
> 
> # search selected lines, forward.
> 
> do list.$first(ktrue) returns #F    <— finds FIRST line where date <= .. but list is sorted in reverse order, so its last date.
> 
> 
> 
> or if you want to sort the list ascending, search for the LAST line
> 
> do list.$sort($ref.TranDate,0)    ## sort ascending
> do list.$search($ref.TranDate<=searchdate,ktrue,kfalse,ktrue,ktrue)
> 
> ## search selected lines, backward
> 
> do list.$first(ktrue,ktrue) returns #F    <— finds LAST line where date <= tran date
> 
> 
> 
> 
> 
> and in reading the $first() documentation there is a third parameter called condition.  I’ve next used it but it implies you could do the following.    Now that I know of the condition….  I may try it in some code
> 
> 
> searchdate=’some date’
> do list.$sort($ref.TranDate,0) 
> 
> and search all lines,   backwards,   with condition
> 
> do list.$first(kfalse,ktrue,$ref.TranDate<=searchdate)
> 
> 
> Doug Easterbrook
> Arts Management Systems Ltd.
> mailto:doug at artsman.com <mailto:doug at artsman.com>
> http://www.artsman.com <http://www.artsman.com/>
> Phone (403) 650-1978
> 
>> On February 14, 2021, at 9:47 AM, Martin Luce via omnisdev-en <omnisdev-en at lists.omnis-dev.com <mailto:omnisdev-en at lists.omnis-dev.com>> wrote:
>> 
>> Hi All
>> 
>> Help please
>> 
>> I have a list of stock transactions with dates. I am trying to get the last transaction date which is less than or equal to the date I am looking at so that I can get what was in stock at the date I am searching on. I cannot see how to do it with notation on a list. I am sure that there must be a way.
>> 
>> Many thanks
>> 
>> Martin
>> _____________________________________________________________
>> Manage your list subscriptions at http://lists.omnis-dev.com <http://lists.omnis-dev.com/>
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com <mailto:omnisdev-en at lists.omnis-dev.com> 
> 



More information about the omnisdev-en mailing list