(getreal "\nEnter the number: ")This means that the user can enter an integer or a real nember.
; BitVal values:
; 0 - only number
; 1 - reject positive (and zero)
; 2 - reject zero
; 4 - reject negative
; 8 - reject real, must be integer
;
; value 3 is equal to 1
; value 11 is equal to 9
; values 5, 7, 13, 15 not have sense > rejects all values
; ex: (ALE_CheckNumber -1 6 nil nil)
;
(defun ALE_CheckNumber (ImpVal BitVal FrmVal ToVal / ErrStr)
(cond
( (or
(not (numberp ImpVal)) ; not number
(and (= 1 (logand 1 BitVal)) (= (abs ImpVal) ImpVal)) ; is positive
(and (= 2 (logand 2 BitVal)) (zerop ImpVal)) ; is zero
(and (= 4 (logand 4 BitVal)) (/= (abs ImpVal) ImpVal)) ; is negative
(and (= 8 (logand 8 BitVal)) (= 'REAL (type ImpVal))) ; is real, not int
(and FrmVal ToVal (not (<= FrmVal ImpVal ToVal))) ; not in range
)
(cond
( (= BitVal 1) (setq ErrStr "The number must be negative") )
( (= BitVal 2) (setq ErrStr "The number must be different from zero") )
( (= BitVal 4) (setq ErrStr "The number must be positive or zero") )
( (= BitVal 8 ) (setq ErrStr "The number must be integer") )
( (= BitVal 6) (setq ErrStr "The number must be positive and different from zero") )
( (= BitVal 9) (setq ErrStr "The number must be integer negative") )
( (= BitVal 10) (setq ErrStr "The number must be integer and different from zero") )
( (= BitVal 12) (setq ErrStr "The number must be integer positive or zero") )
( (= BitVal 14) (setq ErrStr "The number must be integer positive and different from zero") )
( T (setq ErrStr "Value must be a number") )
)
(if (and FrmVal ToVal)
(setq ErrStr (strcat ErrStr " and inclusive among " (ALE_RtoS_DZ8 FrmVal) " and " (ALE_RtoS_DZ8 ToVal) "!"))
(setq ErrStr (strcat ErrStr "!"))
)
)
( ImpVal )
)
)
(defun ALE_RtoS_DZ8 (ReaVal / CurDZn OutVal)
(if (= 8 (setq CurDZn (getvar "DIMZIN")))
(setq CurDZn nil)
(setvar "DIMZIN" 8 )
)
(setq OutVal (rtos ReaVal 2))
(and CurDZn (setvar "DIMZIN" CurDZn))
OutVal
)
Sorry, I should give more details. Here is the portion of my code:Quote(getreal "\nEnter the number: ")This means that the user can enter an integer or a real nember.
I don't want to give the user to choose the type of input by using both "getreal" and "getini" in the code.
(setq a (getreal "\nEnter the number: "))
(if (> (rem a 1) 0)
(setq typ "REAL")
(setq typ "INT")
)
(princ (strcat "\nEntered type is " typ))
(princ)
If it's a real, check the decimal places.(kdub:decimalPlaces a)Code - Auto/Visual Lisp: [Select]
Sorry, I should give more details. Here is the portion of my code:Quote(getreal "\nEnter the number: ")This means that the user can enter an integer or a real number.
I don't want to give the user to choose the type of input by using both "getreal" and "getint" in the code.
;; get precision of a decimal number string including trailing zeros
(defun getPrec (str)
(if (vl-string-search "." str)
(- (strlen str)(vl-string-search "." str) 1)
0
)
)
You never know exactly what the OP wants until you get "That's it" from the OP. 8)
It's quite a dart game answering some of these questions.
You never know exactly what the OP wants until you get "That's it" from the OP. 8)maybe this:
It's quite a dart game answering some of these questions.
; ---------- Source files from: --------------------------------------------
; These functions are freeware courtesy of the author's of "Inside AutoLisp"
; for rel. 10 published by New Riders Publications. This credit must
; accompany all copies of this function.
; Modified by Alessi Marc'Antonio
;
; UINT Funzione di interfaccia utente per numeri interi.
; IGtBit > (0 for none) and KwdStr key word ("" for none) same of INITGET
; PrmStr = prompt string, a default integer will be added
; as <DefInt> (nil for none) and a : will be added
;
; Example:
; (setq #GlVal (uInt 7 "" "How many times" #GlVal))
;
(defun uInt (IGtBit KwdStr PrmStr DefInt / InpVal)
(if DefInt
(setq PrmStr (strcat "\n" PrmStr " <" (itoa DefInt) ">: ")
IGtBit (logand IGtBit 254)
)
(setq PrmStr (strcat "\n" PrmStr ": "))
)
(initget IGtBit KwdStr)
(setq InpVal (getint PrmStr))
(if InpVal InpVal DefInt)
)
;
; UREAL Funzione di interfaccia utente per numeri reali.
; IGtBit > (0 for none) and KwdStr key word ("" for none) same of INITGET
; PrmStr = prompt string, a default real will be added
; as <DefRea> (nil for none), a : will be added.
;
; Example:
; (setq #GlVal (uReal 1 "" "Scale factor" #GlVal))
;
(defun uReal (IGtBit KwdStr PrmStr DefRea / InpVal)
(if DefRea
(setq
PrmStr (strcat "\n" PrmStr " <" (ALE_RTOS_DZ8 DefRea) ">: ")
IGtBit (logand IGtBit 254)
)
(setq PrmStr (strcat "\n" PrmStr ": "))
)
(initget IGtBit KwdStr)
(setq InpVal (getreal PrmStr))
(if InpVal InpVal DefRea)
)
;ALE_RTOS_DZ8 see previous post
Code: [Select]; ---------- Source files from: --------------------------------------------
; These functions are freeware courtesy of the author's of "Inside AutoLisp"
; for rel. 10 published by New Riders Publications. This credit must
; accompany all copies of this function.
< .. >
...if I remember correctly it was around 1990... I continue to use it again!Code: [Select]; ---------- Source files from: --------------------------------------------
; These functions are freeware courtesy of the author's of "Inside AutoLisp"
; for rel. 10 published by New Riders Publications. This credit must
; accompany all copies of this function.
< .. >
That's a familiar blast from the past. :)
Sorry, I should give more details. Here is the portion of my code:Quote(getreal "\nEnter the number: ")This means that the user can enter an integer or a real nember.
I don't want to give the user to choose the type of input by using both "getreal" and "getini" in the code.
(if (zerop (- num (fix num))) (atoi (rtos num)) num)
2 -> 2
2.0 -> 2
2.5 -> 2.5
Hi,
No need to convert to string and convert back:Code - Auto/Visual Lisp: [Select]
@GP, you might need to use (atoi (rtos num 2)) ;-)
No need to convert to string and convert back:
(setq UserInput (getreal "\nEnter the number: "))
(if (UserInput is an integer)
(Option 1 ...)
(progn (Get_Number_of_Decimal) ;;; if the input is a real"
(Option 2 ...)
)
)
(setq a (getreal "\nEnter the number: "))
(if (> (rem a 1) 0)
(setq typ "REAL")
(setq typ "INT")
)
(princ (strcat "\nEntered type is " typ))
(princ)
;; get precision of a decimal number string including trailing zeros
(defun getPrec (str)
(if (vl-string-search "." str)
(- (strlen str)(vl-string-search "." str) 1)
0
)
)
Hi,
No need to convert to string and convert back:Code - Auto/Visual Lisp: [Select]
Here using 2006ACAD I get 2You mean "2" or "2.0", right?
It will accept 2 or 2.0
Here using 2006ACAD I get 2You mean "2" or "2.0", right?
It will accept 2 or 2.0
Note that the argument passed to gile's function is the prompt string to be displayed to the user for the getreal function, not the value to be interpreted.Ooh - I see. Thank you.