Simplicty and flexibility!

Boolean logic in DE8 - Why do I get it IF() wrong when it is right?

Started by DataEase
You will need to Sign In to be able to comment on the Blog!

Boolean logic in DE8 - Why do I get it IF() wrong when it is right?

WIth the introduction of all the SetClass functions and controlling/manipulating forms from virtual fields etc, there has been a lot of support request because users get the syntax wrong even though they are sure it is right.

Mainly this is because you get it right according to the "old" world order ;-)

It is logical to think that if my field is a text field and I do an IF function the return value of that IF function should be text. This is how we have always thought and it has in many ways always worked too...

But with the introduction of SetClass a lot of you that never did chains of actions/functions before have started to use them and then get some trouble that is not straightforward it seems.

But it is..

There is no rule that say that the return value of any function need to be of the same type as the field where you return it and in this way IF is very special. Concat() or Jointext() are string functions but IF is a jack of all trades function.

IF ("A"="B", "Yes,"No") is correct, but IF("A"="B",1,2) is equally correct.
When we add
IF(1=2,"No","YES") into the mix I guess we start to get the drift.

The IF function needs to be balanced so you need to compare apples with apples and return apples and apples or you can compare pares to pears and return apples and apples.

What I am trying to say is that the pears need to match, you need to compare string with string and number with number, and if the return value for true is string the return value for untrue need to be string to

And this is where the confusion happens: "But Sir! I only use String Functions in my Derivation!"

Yes you do, but you add them together and that is what trigger DE to think it is number!

If (YesNoField=Yes,SetState("Field1",1)+SetState("Field2",1)+SetFocus("Field1"),0)

Most of you would put "" as untrue here simply but the correct syntax is number since we add the string functions together.

If we did this however:

If (YesNoField=Yes,Concat("I am clever!",SetState("Field1",1),SetState("Field2",1),SetFocus("Field1")),"")

"" would be the correct counter balancer.

The reason I show both is to also give you an idea. All the SetState return blank string so you can add, concatenate and fire them as part of any derivation without them impacting on the return value...

Written by DataEase 08/10/14 at 12:50:10 Dataease [{8}]FIVE