# Keypad Entry Allowing Values Outside Range

**URL:** <https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511>\
**Category:** Ignition\
**Created:** [May 22, 2012, 5:26pm UTC](https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511 "2012-05-22T17:26:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlr573](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jlr573](https://forum.inductiveautomation.com/u/jlr573)\
**Post date:** [May 22, 2012, 5:26pm UTC](https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511/1 "2012-05-22T17:26:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [May 22, 2012, 5:37pm UTC](https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511/2 "2012-05-22T17:37:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jlr573](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jlr573](https://forum.inductiveautomation.com/u/jlr573)\
**Post date:** [May 22, 2012, 5:42pm UTC](https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511/3 "2012-05-22T17:42:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [May 22, 2012, 6:05pm UTC](https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511/4 "2012-05-22T18:05:02Z")

</div>

No, only if we use those meta values.

---

<div class="post-metadata">

**Author:** ![jlr573](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jlr573](https://forum.inductiveautomation.com/u/jlr573)\
**Post date:** [May 22, 2012, 6:09pm UTC](https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511/5 "2012-05-22T18:09:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [May 22, 2012, 6:32pm UTC](https://forum.inductiveautomation.com/t/keypad-entry-allowing-values-outside-range/4511/6 "2012-05-22T18:32:44Z")

</div>

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.
