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...
Thanks.
4 replies
-
Hi , try the following:
if text(Choice) = "BUY then "It s a BUY" else "It is a SELL" end
-
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.
-
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..." end
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
- 10 mths agoLast active
- 4Replies
- 79Views
-
4
Following