Evaluating text string as a number

I am trying to evaluate the text string in a widget as a number. Basically if someone types in anything between 1 to 7 number range, i want to perform an action. However it looks like it’s not treating it as a number, and evaluating it more as a matching expression? Because if I type a single digit like 9, it seems to work in ignoring it. However if I type 12 , because it has 1, it performs the action when it shouldn’t since it is doesn’t match the criteria

Any ideas how to convert it to a number or properly evaluate this?

Even though it says “text” it is effectively evaluating the values as numbers. Because you are using the Text Changed event, your case is triggered by every change in the value of the text field (regardless if it is a text char or numeric char), so when you enter “1” that is a change, and 1 is less than 8 and greater than 0, so the case evaluates to “true” …But that’s what you want, right? You said you want to perform an action when someone types in “anything between 1 to 7” and that’s what happens.

Solutions for accommodating single and multiple digit numbers would be to use a submit button so the entry is not evaluated until the user clicks the button or hits Enter. You can also set the text field input type to “Number” but if someone uses the “spinner” control to change the number it wouldn’t trigger your Text Changed event, so you’d want to use a submit button as well. You could also use a droplist with preset numbers and use the Selection Changed event.

Ahh, your right, it is actually working right. It only looks like its breaking on double digit numbers because I have to type “1” before the “2” and it’s a onChange event I am using! Thanks!

Another solution came to mind. It looks like you want to perform an action immediately upon number entry and yet still accept someone typing “1” as well as “12”. You could have a delay between a character being entered and the evaluation of the text/number value. Some time duration long enough for a user to normally press the “1” and then the “2” keyboard buttons yet still short enough to perceive the resulting action to be “immediate.” A “Wait 500” ms should do it.

So, you could still have a submit button (and even hide it) then fire this button from the Text Changed (or probably better yet the Key Up event) like so:
Wait 500 ms
Fire Event myButton fire Click or Tap
Then put your conditional cases on “myButton”

Here is a quick demo
multi-digit evaluation.rp (50.0 KB)

1 Like

Thats a great idea the hidden submit. Thanks I will try that!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.