an example:
; 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
)