if statement does not work correctly

This if statement will not return a result:

"ID" = 1

"BD" = 2

"FK" = if("ID">"BD",sqr(("ID"/"BD")^2 - 1),0)

I am guessing that it is because both expressions in the if statement are evaluated, the sqr function fails and therefore the whole expression fails.  I think this bug was also present in SW 2010.  These are the sorts of things that caused me to let my subscription lapse for four years.

SolidworksParts And Features
Answers 3
MM
MM 2013-12-11 Best Answer

Take a look at your math.

1/2 squared = 1/4

1/4 - 1 = -3/4

You are trying to take the square root of a negative number.

Also, for some reason in SW using "iif" instead of "if" seems to work better.

DM
DM 2013-12-11

The if statement should not evaluate the square root function because ID is not greater than BD.

JB
JB 2013-12-17

SolidWorks equations use the VBA IIF ("immediate" or "inline" if).  Even if you use the new "IF" syntax, the underlying function that runs is still VBA "IIF".  When you use IIF, both the "true" and "false" statements are evaluated, regardless of the condition.  Then the result of the proper statement is returned based on the condition.  You can verify this by trying out the equation:

"Dummy" = IIF(1, msgbox("The true part"), msgbox("The false part"))