How to use name of child element in PLC tag?

57 Views Asked by At

I have multiple child elements with different numbers:

ex:

001_Child1

030_Child2

109_Child3

I am trying to create an attribute within a library that will allow me to essentially take the number at the beginning of the child name and assign it to a point within a PLC tag.

Ex:

001_Child1 looks to: PLC(1).Cnt

030_Child2 looks to: PLC(30).Cnt

109_Child3 looks to PLC(109).Cnt

I have tried several Left commands trying to replace 0's and end up just completely removing the 0's in places I dont want, ex: 030 becomes 3 and 109 becomes 19. I have also tried it so i remove just the first two digits, which obviously results in 0 for 030 and 9 for 109. I am just at a loss as to what to do, considering I want to stick to one attribute for the entire thing.

Does anyone know what to do/can help?

1

There are 1 best solutions below

0
On

Solution I came up with:

Attribute 1:

Left(%element%, 3)

Results in 001, 030, 109 etc.

Attribute 2:

Replace('Attribute1', "0", " ")

Results in " 1" or " 3 " or "1 9"

Attribute 3:

LTrim('Attribute2')

Removes all the blanks on the left side.

Results in "1", "3 ", "1 9"

Attribute 4:

Replace('Attribute3', " ", "0")

Replaces all blank spaces with a zero

Results in "1", "30", "109"

So far so good!