Using a given result
Posted: Thu Jun 06, 2013 6:19 pm
Hi guys
I am nearly finished with my whole app but the last part where I seem to be forever going wrong won't work.
The basic idea is for the imputed price to be used to work out how big the percentage should be based on the price and then multiply the price by the percentage and for it to be displayed in a field.
This is probably a maths question because of the results I get.
Here is the whole thing:
Card "Stamp Duty Calculator" Script:
Button code:
I can't believe I still have something wrong I am so incompetent. I tried 3 things with with this:
1) I added the calculate code to the button instead
2) I added it to the card (as is above)
3) I changes the outcomes of the if statement so that the code would follow BODMAS (as is above)
All 3 got different results. Where have I gone wrong please anyone?
ninjabunny14
... still going...
I am nearly finished with my whole app but the last part where I seem to be forever going wrong won't work.
The basic idea is for the imputed price to be used to work out how big the percentage should be based on the price and then multiply the price by the percentage and for it to be displayed in a field.
This is probably a maths question because of the results I get.
Here is the whole thing:
Card "Stamp Duty Calculator" Script:
Code: Select all
function calculatePercentage pType, pPrice
-- the parameters passed to this function have been given more meaningful names
-- check if the pType parameter was "Private" or not
if pType = "Private" then
-- yes it is, so do our other checks on pPrice and return a value accordingly
if pPrice > 2000000.01 then
return (7/100)
else if pPrice > 1000000.01 then
return (5/100)
else if pPrice > 500000.01 then
return (4/100)
else if pPrice > 250000.01 then
return (3/100)
else
return (1/100)
end if
else
-- no pType was not "Private" so return the appropriate value
return 15
end if
end calculatePercentage
on Calculate
put (fld "UO" * (45/100)) into field "ITS fee"
put (fld "ITS Fee" * (20/100)) into field "VAT"
put (fld "ITS Fee" + fld "VAT") into fld "Total Fee"
put (fld "UO" - fld "Total Fee") into fld "Savings"
end Calculate
Code: Select all
on mouseUp
-- get the values from the field and the menu button label and put into variables
-- simply to make it easier to pass them to the function
put the label of button "Purchase Type" into tPurchaseType
put field "Price Input" into tPrice
-- pass those values to the function (which is on the card script so all the buttons on the card can use it)
-- and take the returned value from the function
-- and store it in the destination field
put calculatePercentage (tPurchaseType, tPrice) into field "UO %age"
-- this sends the values in variables tPurchaseType and tPrice to the calculatePercentage function
-- gets the value returned from the function and puts it in the field
put (fld "Price Input" * fld "UO %age") into field "UO"
send "Calculate" to card "Stamp Duty Calculator"
end mouseUp
1) I added the calculate code to the button instead
2) I added it to the card (as is above)
3) I changes the outcomes of the if statement so that the code would follow BODMAS (as is above)
All 3 got different results. Where have I gone wrong please anyone?
ninjabunny14
