Trying a custom handler for several math fields

Graham Samuel livfoss at mac.com
Sun Sep 15 17:29:00 EDT 2013


Hi Vaughn

When you say "the $ is put back into the several fields", are you saying that SOME fields won't have a $ sign in them? If so, then you probably need to keep a note of which fields use the dollar sign and which don't. This is often done by setting a custom property for each field saying something about it, like if it needs a dollar sign, and maybe (if this is an accounting program) whether it should be coloured red if negative etc. We can talk you through this.

If on the other hand the rule is that EVERY field has a dollar sign then it's really simple to take it out before the calculation (maybe using a set of temporary variables to store the actual values to be calculated). There are lots of ways to do this.

I also note that your example is all adding and subtracting - no multiplication or division. If there are in fact multiplications and divisions then you're going to have to think about rounding errors, and a more complex arrangement is needed, since the visible fields will presumably all just have dollars and cents (up to two decimal places), and you may have to keep less truncated versions of the numbers (invisibly) to do the calculations.

None of this is a result of the way LC 'makes' you do things - it's just the difference between the display of numeric values and the values themselves: something Excel is specifically designed to manage behind the scenes.

HTH

Graham

On 15 Sep 2013, at 21:40, Vaughn Clement wrote:

> Hi Geoff
> 
> This is an example of the fields in the handler that need to be in the
> calculation, and when the calculation start the $ will produce an error
> because the $ is in the field. So, the $ needs to be removed, and calc is
> done, then the $ is put back into the several fields.
> 
>   put fld "Loan1" + fld "Loan2" into fld "Loan Balance"
>   put fld "Vehicle Selling Price" - fld "Buyers Offer Discount" into fld
> "Net Offer Price"
>   put fld "Net Offer Price" + fld "Buyers Options Cost" - fld "Factory
> Allowance" into fld "Sum of Offer"
>   put fld "Sum of Offer" - fld "Buyers Accepted Trade" into fld "Net Amt
> after Payoff"
>   put fld "Net Amt after Payoff" - fld "Buyers Down PMT." into fld
> "Balance Before Finance"
>   put fld "Balance Before Finance" + fld "Tax" + fld "Plates" + fld "Doc
> Fees" + fld "Options Other" into fld "Amount of Loan"
>   put fld "Loan Term in Months" * fld "Monthly Payment" into fld "Sum of
> Loan at Term"
>   put fld "Amount of Loan" - fld "Sum of Loan at Term" into fld "Interest
> Paid at Term"
> 
> Thank you
> 
> Vaughn Clement
> 
> Apps by Vaughn Clement (Support)
> *http://www.appsbyvaughnclement.com/tools/home-page/*
> Skype: vaughn.clement
> https://secure.join.me/appsbyvclement
> FaceTime: vclement at gmail.com
> LogMeIn also avaialble
> Call on "ooVoo" at address:  vaughnclement or 9282549062
> Ph. 928-254-9062
> Cloud Hosting Registration Web Site:
> https://my.oditech.com/cart.php?a=add&pid=41
> 
> 
> On Sun, Sep 15, 2013 at 12:35 PM, Vaughn Clement <vclement at gmail.com> wrote:
> 
>> Hi Geoff
>> 
>> For the new developer, can you explain what the script is doing in more
>> detail?
>> 
>> 
>> Thank you
>> 
>> Vaughn Clement
>> 
>> Apps by Vaughn Clement (Support)
>> *http://www.appsbyvaughnclement.com/tools/home-page/*
>> Skype: vaughn.clement
>> https://secure.join.me/appsbyvclement
>> FaceTime: vclement at gmail.com
>> LogMeIn also avaialble
>> Call on "ooVoo" at address:  vaughnclement or 9282549062
>> Ph. 928-254-9062
>> Cloud Hosting Registration Web Site:
>> https://my.oditech.com/cart.php?a=add&pid=41
>> 
>> 
>> On Sun, Sep 15, 2013 at 11:53 AM, Geoff Canyon <gcanyon at gmail.com> wrote:
>> 
>>> In the absence of confirmation from someone looking at the engine code, I
>>> wrote a test. Here are two handlers, with comments explaining what I think
>>> is going on:
>>> 
>>> on mouseUp
>>>   put 1 into X -- X is a number
>>>   put 1 into Y -- Y is a number
>>>   put the long seconds into T
>>>   repeat 9999999
>>>      put X into Z -- Z is a number, no conversion
>>>      add Z to Y -- Z is a number, no conversion
>>>   end repeat
>>>   put the long seconds - T
>>> end mouseUp
>>> 
>>> 
>>> on mouseUp
>>>   put "1" into X -- X is a string
>>>   put 1 into Y -- Y is a number
>>>   put the long seconds into T
>>>   repeat 9999999
>>>      put X into Z -- after the first loop, each time Z has to convert
>>> back
>>> to a string
>>>      add Z to Y -- Z has to be converted to a number
>>>   end repeat
>>>   put the long seconds - T
>>> end mouseUp
>>> 
>>> On my mac, the second handler consistently takes 10% longer to run. Since
>>> the handlers are otherwise identical, I have to think string conversion is
>>> causing the slowdown, and that in the first handler, nothing is being
>>> stored as a string.
>>> 
>>> gc
>>> 
>>> 
>>> On Sat, Sep 14, 2013 at 11:08 PM, <dunbarx at aol.com> wrote:
>>> 
>>>> Geoff.
>>>> 
>>>> 
>>>> I could be misRemembering, possibly even in an earlier life (HC), that
>>>> variable typing was done by the interpreter at runtime, or in HC 2, at
>>>> compile time.
>>>> 
>>>> 
>>>> Maybe this was changed in LC? Someone here must know...
>>>> 
>>>> 
>>>> Craig
>>>> 
>>>> 
>>>> 
>>>> -----Original Message-----
>>>> From: Geoff Canyon <gcanyon at gmail.com>
>>>> To: How to use LiveCode <use-livecode at lists.runrev.com>
>>>> Sent: Sat, Sep 14, 2013 9:10 pm
>>>> Subject: Re: Trying a custom handler for several math fields
>>>> 
>>>> 
>>>> (We agree on all your other points)
>>>> 
>>>> I remember reading many years ago on this mailing list that if you
>>> assign a
>>>> number  to a variable:
>>>> 
>>>> put 52 into x
>>>> 
>>>> LC stores that variable as a number from the get-go and only converts it
>>>> to a
>>>> string if needed.
>>>> 
>>>> Sent from my iPad
>>>> 
>>>> On Sep 14, 2013, at 9:22 AM, dunbarx at aol.com wrote:
>>>> 
>>>>> If you add a number to "50", it is then that the engine types the
>>> string
>>>> as a
>>>> number.
>>>> 
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> use-livecode at 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 at 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 at 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 at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list