I believe it’s sorted (forgive the pun)

As the data is stored in an SQLite db I have used the db to sum the values then 
worked from the top. Like below.

This results in approx. 20ms for each sort direction.

I have looked into a running total calc using SQLite but the solutions I found 
seemed rather complicated.

Sometimes asking for help then presents a solution.

Thanks

Terry

if tOrder is "desc" then

put dbGetAmountForAccount (pAccountName) into tBalance

repeat for each line tRec in tData

put tBalance into item 7 of tRec

put item 6 of tRec into tAmount

subtract (item 6 of tRec) from tBalance

put tRec & CR after tCellData

end repeat

delete last char of tCellData

else

repeat for each line tRec in tData

add item 6 of tRec to tBalance

put tBalance into item 7 of tRec

put tRec & CR after tCellData

end repeat

delete last char of tCellData

end if


> On 29 Mar 2020, at 14:20, Brian Milby via use-livecode 
> <use-livecode@lists.runrev.com> wrote:
> 
> Is there a key that you can use to sort?  May be faster to build it and then 
> use the sort command at the end.
> 
> Thanks,
> Brian
> On Mar 29, 2020, 7:16 AM -0400, Tore Nilsen via use-livecode 
> <use-livecode@lists.runrev.com>, wrote:
>> I believe the reason for the delay comes from the fact that when sorted 
>> descending, you put tRec & CR before tCellData. Tp put something before a 
>> container is slower than putting something after a container.
>> 
>> Regards
>> Tore Nilsen
>> 
>>> 29. mar. 2020 kl. 13:06 skrev Terence Heaford via use-livecode 
>>> <use-livecode@lists.runrev.com>:
>>> 
>>> I have approx. 7000 lines of tab delimited data.
>>> 
>>> When I execute the code snippet below if the sort order is descending it 
>>> takes approx 120 milliseconds otherwise it takes 20 milliseconds to process.
>>> 
>>> Can someone explain why and perhaps come up with a faster solution.
>>> 
>>> Thanks
>>> 
>>> Terry
>>> ——————————
>>> 
>>> repeat for each line tRec in tData
>>> 
>>> add item 6 of tRec to tBalance
>>> 
>>> put tBalance into item 7 of tRec
>>> 
>>> 
>>> switch tOrder
>>> 
>>> case "desc"
>>> 
>>> put tRec & CR before tCellData
>>> 
>>> break
>>> 
>>> default
>>> 
>>> put tRec & CR after tCellData
>>> 
>>> end switch
>>> 
>>> 
>>> end repeat
>>> 
>>> 
>>> switch tOrder
>>> 
>>> case "desc"
>>> 
>>> delete char 1 of tCellData
>>> 
>>> break
>>> 
>>> default
>>> 
>>> delete last char of tCellData
>>> 
>>> end switch
>>> 
>>> -------------------
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode@lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your 
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription 
>> preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to