Handler or function
Mark Schonewille
m.schonewille at economy-x-talk.com
Sun Aug 6 15:13:45 EDT 2006
Hi Liam,
Whether you should use a function rather than your handler really
depends on what you want. If you really need to display intermediate
values, you might want to use the following relatively short handler
on fCal
set the numberFormat to "#0.00"
put (fld "Adult" * fld "aPrice") into fld "AdultPrice"
put (fld "Child" * fld "cPrice") into fld "ChildPrice"
put (fld "Other" * fld "oPrice") into fld "AdultPrice"
put (fld "Adult" * fld "aPrice") + (fld "Child" * fld "cPrice") ¬
+ (fld "Other" * fld "oPrice") into field "Total"
end fCal
but if that's not necessary, the first and the last line of above
handler would be sufficient
on fCal
set the numberFormat to "#0.00"
put (fld "Adult" * fld "aPrice") + (fld "Child" * fld "cPrice") ¬
+ (fld "Other" * fld "oPrice") into field "Total"
end fCal
and if you need to do this really, really often and you get tired of
typing the syntax all the time, I would try to use shorter variable
names together with this function:
function gCalc
theaPrice,thecPrice,theoPrice,theChildNumber,theAdultNumber,theOtherNumb
er
set the numberFormat to "#0.00"
return (theAdultNumber * theaPrice) + (theChildNumber * thecPrice)
+ (theOtherNumber * theoPrice)
end gCalc
If you are going to repeat these calculations hundreds of times, you
really don't want to update the fields all the time, because it
reduces performance. Otherwise, you could use your original handler
as well.
Best,
Mark
--
Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz
Download ErrorLib at http://economy-x-talk.com/developers.html and
get full control of error handling in Revolution.
Op 6-aug-2006, om 20:45 heeft Liam Lambert het volgende geschreven:
> Sorry Typo
> Should have said
> Hi all I have am using this handler to calculate different prices
> for children adults and others
> The aPrice cPrice and the oPrice are different prices selected from a
> fld with different prices in it
> the handler works fine my question is should I do this with a
> function
> or is there a better way to do this
>
>
> on fCal
> set the numberFormat to "#0.00" -- dollar format
> put field "aPrice" into theaPrice -- the selected adult price
> Put field "cPrice" into thecPrice -- the selected child price
> put fld "oPrice" into theoPrice ---other selected price
> put field "child" into theChildNumber --the number of children
> put field "adult" into theAdultNumber --the number of adults
> put fld "other" into theOtherNumber ---the number of other
>
> put (theChildNumber * thecPrice) into field "Childprice"-- * the
> number of children by the price
> put (theAdultNumber * theaPrice) into field "Adultprice"-- * the
> number of Adults by the price
> put (theOtherNumber * theoPrice) into fld "Otherprice"
>
> put field "Childprice" into theChildprice
> put field "Adultprice" into theAdultprice
> put fld "Otherprice" into theOtherPrice
> put theAdultprice + theChildprice + theotherPrice into field
> "Total"
> end fCal
>
> Thank's Liam
>
>
> IRELAND
> liamlambert at mac.com
>
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list