Following is a sub-function within a program which increments numbers in mtext or text strings.
Input needs to be a number, and should allow values like .25 or 25 or 25.0. The numeric value returned should not be altered in any way. Except for converting input ..25 to 0.25 to avoid the "misplaced dot on input" error. Input integer, return integer. Input real, return real. Input something that doesn't represent a number, loop until a number is entered.
(defun GetNumber ( message / num )
(princ message)
(setq num (getstring))
(if (= "." (substr num 1 1))
(setq num (strcat "0" num))
)
(if (numberp (read num))
(read num)
(GetNumber "Value must be a number: ")
)
) ;end
Seems to work:
Command: (GetNumber "Input value: ")
Input value: .25
0.25
Command: (GetNumber "Input value: ")
Input value: 25
25
Command: (GetNumber "Input value: ")
Input value: 25.0
25.0
Command: (GetNumber "Input value: ")
Input value: a
Value must be a number: 25
25
Comments, suggestions and spitballs welcome.
Joe Burke
Input needs to be a number, and should allow values like .25 or 25 or 25.0. The numeric value returned should not be altered in any way. Except for converting input ..25 to 0.25 to avoid the "misplaced dot on input" error. Input integer, return integer. Input real, return real. Input something that doesn't represent a number, loop until a number is entered.
(defun GetNumber ( message / num )
(princ message)
(setq num (getstring))
(if (= "." (substr num 1 1))
(setq num (strcat "0" num))
)
(if (numberp (read num))
(read num)
(GetNumber "Value must be a number: ")
)
) ;end
Seems to work:
Command: (GetNumber "Input value: ")
Input value: .25
0.25
Command: (GetNumber "Input value: ")
Input value: 25
25
Command: (GetNumber "Input value: ")
Input value: 25.0
25.0
Command: (GetNumber "Input value: ")
Input value: a
Value must be a number: 25
25
Comments, suggestions and spitballs welcome.
Joe Burke