Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

EDIT BOX input to REAL or INTEGER

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
hcanas
1454 Views, 10 Replies

EDIT BOX input to REAL or INTEGER

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)
)

DC
10 REPLIES 10
Message 2 of 11
mracad
in reply to: hcanas

Here is a test to see type of value (cond ((= (itoa (atoi V1)) V1) (alert "Integer")) ((wcmatch V1 "*`.*") (alert "Real")) ((= V1 "") (alert "Blank")) (T (alert "String")) )
Message 3 of 11
_gile
in reply to: hcanas

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 !!")



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 11
_gile
in reply to: _gile

mracad,

 

Try (wcmatch "foo.bar" "*`.*")



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 11
hcanas
in reply to: mracad

thank a lot mracad... got it.

DC
Message 6 of 11
hcanas
in reply to: hcanas

thank you to all....

DC
Message 7 of 11
_gile
in reply to: hcanas


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 !!")

)



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 11
_gile
in reply to: hcanas

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) ) )" )


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 11
hcanas
in reply to: _gile

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)))"
)

DC
Message 10 of 11
_gile
in reply to: hcanas

Hi,

 

If it's always the same default value, you can set it in the DCL file:

:edit_box { key = "e1"; value = "12345"; ... }

 

If not, you can initialze it from the calling LISP:

(set_tile "e1" "12345")

or

(set_tile "e1" (atof Pr#))

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 11
hcanas
in reply to: _gile

thank you a lot _gile...  Smiley Happy

DC

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost