Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

If then else statements

Avatar

Former Community Member
Hello I have this FormCalc if-then-else statement and I can't figure out where I am going wrong. I keep getting this error of a sytnax error near token 'then' on line 7. Prior to this I could only get the script to work for a maximum of 3 elseif's.:



if ( WEIGHT < 1000 ) then

SHIP = 9.50



elseif (1001 < WEIGHT < 2000) then

SHIP=9.85



elseif (2001 < WEIGHT < 3000) then

SHIP=10.50



elseif (3001 < WEIGHT < 3500) then

SHIP=11.50



elseif (3501 < WEIGHT < 4000) then

SHIP=12.50



elseif (4001 < WEIGHT < 4500) then

SHIP=13.50



elseif (4501 < WEIGHT < 5000) then

SHIP=14.50



else (WEIGHT > 5001) then

SHIP=15.50



endif



Any help is appreciated.
8 Replies

Avatar

Former Community Member
The last statement is

"

else (WEIGHT > 5001) then

SHIP=15.50

"

It doesn't look correct or do you copy/paste correctly?



It can be

"else SHIP=15.50"

or

"elseif (WEIGHT > 5001) then SHIP=15.50"



Henry

Adobe

Avatar

Former Community Member
In other words, you can't attach a condition to an ELSE statement; ELSE is a catch-all for all other conditions.



Where you say

else (WEIGHT > 5001) then

that is already assumed.

Avatar

Former Community Member
The expression (1001 < WEIGHT < 2000) doesn't seem right for me. You may try something like:<br />"<br />if ( WEIGHT < 1000 ) then SHIP = 9.50<br />elseif ((1001<WEIGHT) and (WEIGHT<2000)) then SHIP=9.85<br />"<br />Henry<br />Adobe

Avatar

Former Community Member
Furthermore, I don't think the following is allowed in FormCalc:



elseif (
4001 < WEIGHT < 4500) then SHIP=13.50


I believe you have to use the following syntax:



elseif (
4001 < WEIGHT & WEIGHT < 4500) then SHIP=13.50


When "4001 < WEIGHT" is evaluated, it amounts to a "true" or "false" value. Writing it the first way would essentially result in comparing "true" or "false" to 4500 which likely isn't what you want to do here.



The suggested way to write the expression boils-down to evaluating two boolean ("true" or "false") values together with an "and" operator which makes more sense (where the shipping cost is 13.50 only if the weight is both larger than 4001
and smaller than 4500).



Stefan

Adobe Systems

Avatar

Former Community Member
Thank you very much for your assistance. The form seems to be calculating just fine now.

Avatar

Level 1
I found this very helpful, thanks.



Having got this to work in my form I want to make the last figure a text line, not numerical. I.e. If the postage goes above a certain price point the customer must contact the office "POA".



I can't get it to put in anything but $0.00 at that point.

Avatar

Former Community Member
Denise,



This is most likely because you're assigning the value "POA" (a string) to a numeric field. Assigning a string value to a field which expects a numerical value always results in a translated numerical value of zero (0).



There are a few solutions I could suggest but I think the easiest one would be to use what's called a "compound" pattern for the Display Pattern property of the numeric field, located on the Object palette's Field tab.



Compound Display Patterns are patterns that include multiple "inner" patterns that tell a field how to display its data in different circumstances. For example, if the field's value (data) is null (no specified value -- not even zero), the field could display "POA" (text even though it's a numeric field). Otherwise, when the field's value is specified (not null), it could display it using a normal numeric pattern such as "$z,zz9.99".



So let's say you've already specified a Display Pattern of "$z,zz9.99" for the numeric field. You would change this Display Pattern into the following compound pattern:



null{'POA'}|num{
$z,zz9.99}



Notice that the original Display Pattern has been preserved but now the compound pattern includes information on what to do when the field's value is null (not specified).



Given this compound pattern, when the postage goes above a given price, you would simply assign "null" as a value to the numeric field and it would automatically display a value of "POA" (even though it wouldn't actually have a value).



To set a field to null in FormCalc, you can do this:



NumericField1 = Null


And in JavaScript:



NumericField1.rawValue = null;


Stefan

Adobe Systems

Avatar

Level 1
Thank you very much for this excellent help. It now works perfectly.