Why using a choice field's text does not work in an "if" statement?

Hi all.

Using the number next to the choice's text in an "if" statement works.  Using the text part does not.  Why?  Looked  in the documentation, the only example I could find does use the number, but does not say why...  Not logical...



4 replies

    • szormpas
    • 3 mths ago
    • Reported - view

    Hi  , try the following:

    if text(Choice) = "BUY then "It s a BUY" else "It is a SELL" end

      • M_ichel.1
      • 3 mths ago
      • Reported - view

      YES!!!  Thank you!

    • John_Halls
    • 3 mths ago
    • Reported - view

    If you can resist the temptation to use the text, and use the index number instead your code will be better. Using the text would be considered as hardcoding your software, which can cause problems later on. For instance, if you decide to change your text from "BUY" to "PURCHASE" your code will break, but the index would still be 1 and by  using this your code would still work.

    • Kruna
    • 3 mths ago
    • Reported - view

    Just to put my two cents in, you can also use switch case statement like

    switch choice do
    case 1: "It is a BUY"
    case 2: "It is a SELL"
    default "Please choose..."

    As default is optional you can leave it out, if there is no need for it.

    So here you can add another options and easily code with eg case 3, case 4 etc.

    Note that case number matches option number.

Content aside

  • 3 mths agoLast active
  • 4Replies
  • 75Views
  • 4 Following