I need to translate V1 into a REAL or INTEGER but i got the alert all the time.
what i doing wrong.. please help
from the EDIT BOX, I get the value of e1 => bbedit_box { key = "e1";
in the lisp is translated to V1:
(action_tile "accept" "(setq v1 (get_tile \"e1\")) (done_dialog)")
(setq v2 (atof v1)) ; string to real = T
(if (/= numberp v2) ; evaluate if is real or integer
(progn (alert "The Input are not NUMBERS !!")
(C:TEST1)
)
Solved! Go to Solution.
Solved by hcanas. Go to Solution.
Hi
(/= numberp v2) wille always T because you're comparing a function (numberp) with a number (v2).
More, using (atof v1) will always return a number. Try: (atof "any string"), it will return 0.0
You'd rather use distof which returns nil if the string passed as argument doesn't represent a number (or a fraction) so you can set the v2 value and test it validity at the same time:
(if (setq v2 (distof v1)) ; bounds the value and evaluate if is real or integer
(progn (alert "The Input are not NUMBERS !!")
hcanas a écrit :
thank a lot mracad... got it.
As I said, the (cond ...) statement mracad purposed is not safe.
(atoi "12.5foo") returns 12
(wcmatch "foo.bar" "*`.*") returns T
Use instead distof as I purposed or
(if (numberp (read v1)) ; evaluates if the string represent a number
(setq v2 (atof v1))
(alert "The Input are not NUMBERS !!")
)
IMO, a better way should be evaluating the input validity within the (action_tile "accept" ...) expression so that you can call (done_dialog) only if the input is a valid number:
(action_tile "accept" "(if (numberp (read (get_tile \"e1\")))
(progn
(setq v1 (get_tile \"e1\")) (done_dialog)
) (progn (alert \"The Input are not NUMBERS !!\") (mode_tile \"e1\" 3) ) )" )
Thank you guys...
_gile that work perfect....
now I have another question... how to put a pre-Fill number within the editbox (be able to changed)..
if a have the variable "Pr#" with the number 12345, any sugestions ?
(setq Pr# "12345")
(action_tile "accept" "(if (numberp (read (get_tile \"e1\")))
(progn (setq v1 (get_tile \"e1\")) (done_dialog))
(progn (alert \"The Input are not NUMBERS !!\")
(mode_tile \"e1\" 3)))"
)