Indirect tag string?

how would I write a value to a tag where the tag name changes depending on a variable?


I have a bunch of tags - ‘PN001’ through ‘PN100’

and I have a variable that defines what the number portion of the tag is, so i want to add “PN” to my variable and then use this value as the tag… something like this:

value = 500
x = PN
variable = 001
tag = str(x + variable)
system.tag.writeToTag(tag, value)

thank you.

Since the “tag” variable that is passed via system.tag.writeToTag needs to be a string, you have to make sure the value inside that variable is indeed a string. You can do this with either string concatenation or string substitution, concatenation should be more efficient however. Putting the values for the variables in quotes, and using the concat operator (+) will do the trick:

value = 500
x = “PN”
variable = “001”
tag = x + variable
system.tag.writeToTag(tag, value)

thank you, thats what I was missing. :smiley: