Splitting formatted text field into two integer tags

Hi,

I created formatted text field with format of ##:## so the client can enter the time in hours and minutes. but i need to split the number entered into two integer tags to send back to the PLC. one tag for the hours and one tag for the minutes.
I tried the following script in the formatted text field property change but its not working:
(i need your help please)

if event.propertyName == “committedValue”:
newText = “committedValue”.split(":")
value0 = newText[0]
value1 = newText[1]
value2 = toint(value0)
value3 = toint(value1)
system.tag.writeToTag(“tagname”, value2)
system.tag.writeToTag(“tagname”, value3)

if event.propertyName == 'committedValue':
	newText = event.source.committedValue.split(':')
	hour = int(newText[0])
	minute = int(newText[1])
	
	system.tag.write('hourTag', hour)
	system.tag.write('minuteTag', minute)
1 Like

THANK YOU :slight_smile:
finally its working

Thanks for the support. but now i have another question.
on the same formatted text field can i read the time from the same tags i used for hours and minutes???

Sure, you just need to use the system.tag.read() function. You can also use the readAll function, which will be more efficient if you’re reading several tags. Keep in mind that these are returning qualified value objects (value, quality and timestamp).

#This will return a qualified value object
tag = system.tag.read(tagPath)

# Access the tags value, quality and timestamp
tagValue = tag.value
tagQuality = tag.quality
tagTime = tag.timestamp

https://docs.inductiveautomation.com/display/DOC79/system.tag.read
https://docs.inductiveautomation.com/display/DOC79/system.tag.readAll