Expand my Community achievements bar.

FormCalc & "IF" statement

Avatar

Former Community Member
I'm working on a form that needs to calculate tax based on which province the person selects, different rates for each province, different types of calculations for two.



I have set up a drop down box for the selection of province.



I have to calculate tax as follows



Province Tax

AB 6%

BC 13%

MB 13%

NB 14%

NL 14%

NT 6%

NS 14%

NV 6%

ON 14%

PE 6%, plus 10% calculated on base amount plus 6% tax

QC 6%, plus 7.5% calculated on base amount plus 6% tax

SK 13%

YT 6%



The formula I have written is shown below, but every time I put it into the software, then try and save it the program hangs up on saving, crashes and corrupts the file. Is it because my formula is too big?



( if ( Province = "AB" , ( SalePrice * .06 ) , if ( Province = "BC" , ( SalePrice * .13 ) , if ( Province = "MB" , ( SalePrice * .13 ) , if ( Province = "NB" , ( SalePrice * .14 ) , if ( Province = "NL" , ( SalePrice * .14 ) , if ( Province = "NT" , ( SalePrice * .06 ) , if ( Province = "NS" , ( SalePrice * .14 ) , if ( Province = "NV" , ( SalePrice * .06 ) , if ( Province = "ON" , ( SalePrice * .14 ) , if ( Province = "SK" , ( SalePrice * .13 ) , if ( Province = "YT" , ( SalePrice * .06 ) , if ( Province = PE , ( ( SalePrice * .06 ) + ( ( SalePrice * 1.06 ) * .1 ) , if ( Province = QC , ( ( SalePrice * .06 ) + ( ( SalePrice * 1.06 ) * .075 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )



Looking forward to any ideas!



Kathryn
4 Replies

Avatar

Former Community Member
I'm not sure why it is crashing but you might try a switch statement instead...

var val = 0;

switch(Province )

{

case "AB":

val = SalePrice * .06 ;

break;

case "BC":

val = SalePrice * .13 ;

break;

case "NB":

val = SalePrice * .14 ;

break;

// etc

}



val



Rich Ruiz

Novanis



}

Avatar

Former Community Member
Well, certainly that formula would never work in any case, since it's not FormCalc. Check out the FormCalc reference that comes in the documentation directory to see how to write an if statement in FormCalc.



Rich's idea is better, but be aware it's JavaScipt not FormCalc. FormCalc has no switch statement as far as I know.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
New to this in Adobe, thanks for the suggestion, looking forward to trying it out on my form tonight.



Thanks!!!



Kathryn

Avatar

Former Community Member
Not sure if you found your answer by now, but here's a simple if statement in formcalc that I've used.



if (REGION1 == "BC) then

Round(((Calc1)*.06), 2)



elseif (REGION1 == "AB") then

Round(((Calc1)*.06), 2)



elseif (REGION1 == "SAS") then

Round(((Calc1)*.06), 2)



elseif ((REGION1 == "MAN") then

Round(((Calc1)*.06), 2)



elseif (REGION1 == "ONT") then

Round(((Calc1)*.06), 2)



elseif (REGION1 == "QUE") then

Round(((Calc1)*.06), 2)



elseif (REGION1 == "NB") then

Round(((Calc1)*.14), 2)



elseif (REGION1 == "NWT") then

Round(((Calc1)*.06), 2)



endif