Unable to get toInt to work

Unable to get toInt to work. I have a OPC tag that is a String and I want to convert it to an INT. I have created an expression tag with toint ({[.]Alarm Code.value},-1). Most of the time it reports back -1 but every once in a while it shows the correct value of the other tag then goes back to -1 even thought the string value is 31.

While I don't think it should matter, try making it just toInt({[.]Alarm Code}, -1) to remove the .value as it's the default anyway, but not sure if it could cause any issues with what you're seeing. Also, I'm assuming this is inside a UDT since you're using [.]. Are there any spaces or other "hidden" characters part of the string that could be causing an error when it reads -1?

That was the way I had it originally and I did just try again to no aval. I did just try renaming the original tag taking out the space and im still having the same issue.

What about wrapping the tag in a trim() function as well as a precaution?

toInt(trim({[.]Alarm Code}), -1)

That worked, Question why did that work?

Most likely some extra whitespace or characters you possibly weren't seeing that it stripped off before trying to convert to an integer.

Perfect, Thank you for your help. Was really banging my head on this simple one.