Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
on keyDown thekey
If thekey is not a number then answer information "Must be a number"
else pass keyDown
PUT me into nareasqm
end keyDown
However when I test it, it will not let me enter a decimal point eg. 27.5 yet the Dictionary says a Number can have decimal place. So is this a glitch with LC or is my code doing something to make it think it's an Integer
The issue is that LC is evaluating each char in each keypress to see if it is a number. So though it is true that "27.5" is a number , it is also true that "." is not.
on textchanged
put 0 into k
repeat for each line L in me
add 1 to k
if L is not a number then
select line k of me
exit repeat
end if
end repeat
end textchanged
Your handler will somewhat guard against non-numeric entry. It is a little too tough on the user, though, eh? If you type a series of digits and then a "K", it deletes the whole line on the next keypress. And if you type "55X" and manually select the next line, it keeps that string intact.
I suggest to pre-validate the keypress itself instead of evaluating the line after the entry.
Craig.
Right, of course the user should set what to do if non-numbers were inserted.
But catching keypresses doesn't handle paste, not "1.." what is not even a version number and also not negative numbers.
on keyDown tkey
put word 2 of the selectedLine into tLine
if tKey = "-" and "-" is in line tLine of me then exit to top
if tKey = "+" and "+" is in line tLine of me then exit to top
if tKey = "." and "." is in line tLine of me then exit to top
if tkey is in "0123456789-+." then pass keyDown
end keyDown
on keyDown thekey
If me & thekey is not a number then answer information "Must be a number"
else pass keyDown
end keyDown
This assumes the entry is after the existing text though and will fail if the selection is in the middle somewhere. An alternative would be to use keyup and remove the last entry if the text isn't a number.
Last edited by jacque on Fri Dec 21, 2018 6:39 pm, edited 1 time in total.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com