If statements on expression binding on a labels text property

How do I do something like this on a text prop of a label. I want the label to change based on the dropdown selection.

if {../Dropdown.props.value} = 0 
	....
if {../Dropdown.props.value} = 1
	...

Use an expression binding.

case({../Dropdown.props.value},
    1, "A partridge in a pear tree",
    2, "Two turtle doves",
    3, "Three French hens",
    4, "Four calling birds",
    5, "Golden rings",
    "Unknown 12 Days of Christmas gift"
)

https://docs.inductiveautomation.com/display/DOC81/case

3 Likes

Merry Christmas !

1 Like

As an aside, you can't write programs in an expression. Think of them like Excel functions. To make your expression work with if you would need,

if(({../Dropdown.props.value} = 1,
  "A partridge in a pear tree",
  if({../Dropdown.props.value} = 2, 
      "Two turtle doves",
      if({../Dropdown.props.value} = 3, 
        "Three French hens",
        if({../Dropdown.props.value} = 4, 
          "Four calling birds",
          if({../Dropdown.props.value} = 5, 
            "Golden rings",
            "Unknown 12 Days of Christmas gift"
)))))

It's not pretty!

1 Like

the comma after "tree" needs to be outside the quotation mark.

Fixed, thanks.
Merry Christmas!