I have a integer tag 0-9 and want to display a string that corresponds to the integer.
How would I do that using a switch statement…
so when tag is 0, it should say zero, when changes to 1 should say one…and so on.
Thanks.
I have a integer tag 0-9 and want to display a string that corresponds to the integer.
How would I do that using a switch statement…
so when tag is 0, it should say zero, when changes to 1 should say one…and so on.
Thanks.
[size=150]Option 1: Bind the Text Property of the label to an expression:[/size]
switch({Test/IntergerTag},
0,1,2,3,4,5,6,7,8,9,
"zero","one","two","three","four","five","six","seven","eight","nine",
"ERROR"
)
[size=150]Option 2: If you’re really, really looking to use a python dictionary:[/size]
I created a shared script called convert. in it:
def int2Name(value):
dict={0:"zero", 1:"one", 2:"two", 3:"three", 4:"four", 5:"five", 6:"six", 7:"seven", 8:"eight", 9:"nine"}
if value in dict:
return dict[value]
else:
return "ERROR"
EDIT: Cleaned up script to make dictionary a bit more manageable.
Then bind the Text Property to the expression:
runScript(concat("shared.convert.int2Name(",toStr({Test/IntergerTag}),")"),500)
Is referencing allowed in expression binding? Like if I have many paths but referenced by their numbers…
{Folder1/Option1/Selection1/Integer_Tag} to
{Folder%d/Option%d/Selection%d/Integer_Tag} % ({folder_num}, {option_num}, {selection_num})
It says it is not valid path for some reason.
I’d make a Custom property to handle that portion of it, then reference the custom property in the runscript()
Well, I am getting confused with that, so I tried using the simplest way just having one Label read the tag and another display the corresponding names from the Label that reads the integers but that too doesn’t work neither.
if event.source.propertyName == "text":
target = event.source.parent.getComponent('Display num')
if event.source.text == 0:
target.text = "Zero"
elif event.source.text == "1":
target.text = "One"
elif event.source.text == "2":
target.text = "Two"
elif event.source.text == "3":
target.text = "Three"
elif event.source.text == "4":
target.text = "Four"
elif event.source.text == "5":
target.text = "Five"
elif event.source.text == "6":
target.text = "Six"
elif event.source.text == "7":
target.text = "Seven"
elif event.source.text == "8":
target.text = "Eight"
elif event.source.text == "9":
target.text = "Nine"
Are you trying to do this in a property binding? I’m just wondering if may be confusing expression language with scripting language. They are separate entities.