0

Switch statement evaluating to default value

switch 'FL Value' do
case 'FL Value' > 48.3389 and 'FL Value' < 57.7777:
text("A")
case 'FL Value' > 40.0056 and 'FL Value' < 48.3388:
text("B")
case 'FL Value' > 32.7833 and 'FL Value' < 40.0055:
text("C")
case 'FL Value' > 26.6722 and 'FL Value' < 32.7832:
text("D")
case 'FL Value' > 21.6722 and 'FL Value' < 26.6721:
text("E")
case 'FL Value' > 15.5611 and 'FL Value' < 21.6721:
text("F")
case 'FL Value' > 8.3389 and 'FL Value' < 15.5611:
text("G")
case 'FL Value' > 0.0056 and 'FL Value' < 8.3388:
text("H")
case 'FL Value' > -9.4389 and 'FL Value' < 0.0055:
text("I")
case 'FL Value' > -18 and 'FL Value' < -9.439:
text("J")
case 'FL Value' < -18.0001:
text("K")
default:
text("Z")
end

FL Value is 22, but the formula is evaluating "Z", the default value, it should evaluate to "E", since 22 is within the range 21.6722 and 26.6721, Where is the error.

4 replies

null
    • Sean
    • 4 yrs ago
    • Reported - view

    You can only use an expression in the switch part of the statement and the result of that expression is compared to the case values. If you changed your first case statement to...

     

    case 48.3389:

     

    it would be a valid case statement and would return "A" if 'FL Value' was 48.3389. I think you have to use nested if-then-else statements to do what you want.

    • Sean
    • 4 yrs ago
    • Reported - view

    OK, scratch that previous post. I remembered a post from last August that is similar to what you are wanting to do. Change the switch statement to...

     

    switch 'FL Value' > -20 and 'FL Value' < 50 do

     

    You can change the -20 and 50 to values you want to use. All the case statements are unchanged.

    • subzwari
    • 4 yrs ago
    • Reported - view

    Thank you for your advise, I will make the suggested changes.

    • subzwari
    • 4 yrs ago
    • Reported - view

    I made the changes and now it’s evaluating as expected. Thank you for helping me here.

Content aside

  • 4 yrs agoLast active
  • 4Replies
  • 3064Views