|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Jan 15, 2017 2:43 am Post subject: Accepting positive / negative value via textbox |
|
|
In connection with this : http://forum.cheatengine.org/viewtopic.php?t=602490
How to make edit box (Text box) only accept positive or negative number value ?
Tried 1 :
Code: | f = createForm()
e = createEdit(f)
pattern = {"1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , - , . "}
function fixNumber(text)
if (text:gmatch(pattern)== nil) then
showMessage("Value not accepted")
else
showMessage("Value ok..")
Not work
end
end
text = e.Text
e.onChange = fixNumber |
Tried 2 :
Code: | function dvalCheck(sender)
local Num = sender.text
if type(Num) == "number" then
return Num >= 0 or Num <= 0 and Num or -Num
-- local Num = tonumber(sender.text)
sender.font.color == "0x00ff0000"
--if Num == nil then
else
sender.font.color == "0x000000ff"
showMessage("Invalid Number")
return
end
end
UDF1.CEEdit1.onChange = dvalCheck
--- // trying implementing this :
function abs(x)
assert(type(x) == "number", "abs expects a number")
return x >= 0 or x <= 0 and x or -x
end
|
Thank so much for any solutions given...
|
|
Back to top |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8516 Location: 127.0.0.1
|
Posted: Sun Jan 15, 2017 3:49 am Post subject: |
|
|
Something like this maybe:
Code: | function fixNumber(str)
return tonumber(str) ~= nil and (string.match(str, '[^%d\-\.]') == nil);
end |
For your type of example:
Code: | f = createForm()
e = createEdit(f)
function fixNumber(o)
-- Get the edit text..
local text = e.Text;
-- Validate its a number..
if (tonumber(text) ~= nil or (string.match(text, '[^%d%-%.]') == nil)) then
-- valid number..
else
-- invalid, reset the edit text..
e.Text = '';
end
end
e.onChange = fixNumber;
|
_________________
- Retired. |
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Sun Jan 15, 2017 4:56 am Post subject: |
|
|
Thank so much atom0s
Fix and work properly. text box only accepting 0 - 9, negative, double and float value.
Code: | f = createForm()
e = createEdit(f)
function fixNumber(sender)
local text = sender.text
if (tonumber(text) ~= nil or (string.match(text, '[^%d%-%.]') == nil)) then
sender.font.color = "0x00ff0000"
else
sender.font.color = "0x000000ff"
showMessage("Invalid Number")
return
e.Text = ''; end
end
e.onChange = fixNumber;
f.show() |
Regards
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|