Keypad Entry Allowing Values Outside Range

I’m working on a script that shouldn’t allow a value to get passed through to the PLC if it outside the range. But the value is getting passed to the PLC when it is outside the range.

[code]
spLow = event.source.parent.getComponent(‘ledSetpointLow’).value
spHigh = event.source.parent.getComponent(‘ledSetpointHigh’).value
keyPad = event.source.getComponent(‘ledSetPointSpeed’).value = system.gui.showNumericKeypad(event.source.getComponent(‘ledSetPointSpeed’).value)

if keyPad <= spLow:
system.gui.warningBox(“Setpoint too Low”)

elif keyPad >= spHigh:
system.gui.warningBox(“Setpoint too High”)

else:
keyPad[/code]

I’m thinking there is something I might be missing in the script to cancel the action if the value is outside the range.

You need to do something like this:[code]spLow = event.source.parent.getComponent(‘ledSetpointLow’).value
spHigh = event.source.parent.getComponent(‘ledSetpointHigh’).value
keyPad = system.gui.showNumericKeypad(event.source.getComponent(‘ledSetPointSpeed’).value)

if keyPad <= spLow:
system.gui.warningBox(“Setpoint too Low”)
elif keyPad >= spHigh:
system.gui.warningBox(“Setpoint too High”)
else:
event.source.getComponent(‘ledSetPointSpeed’).value = keyPad[/code]You only set the property when the value is in the right range. Before you were setting it at the same time you return it from the showNumericKeypad function.

I see what I did wrong, Thanks. But if those high and low values are put on the tags EngLow and EngHigh meta properties shouldn’t the error be caught there before it’s passed to the PLC?

No, only if we use those meta values.

Use them in the script? Because the event.source.parent.getComponent(‘ledSetpointLow’).value and event.source.parent.getComponent(‘ledSetpointHigh’).value are bound to those meta properties.

Right, you are using them in the script. If you didn’t have the if checks the showNumericKeypad doesn’t know what the high and low are.