PDA

View Full Version : Restrict User Input to certain Digits of characters



lalit_jangid
2014-01-02, 04:57 AM
Hello Augi Members,

I have created some of simple Lisp programs, in some program I want to restrict user to input only single value (i.e. one or two or three digits) & as the digits are filled it takes "enter" command automatically.

Can anyone help me out of this.

Thanks in advance.

-Lalit

Tharwat
2014-01-02, 05:17 AM
Did you try getint function ?

cadtag
2014-01-03, 06:28 PM
GRREAD maybe? (getint) will still require the operator to hit Enter.

rkmcswain
2014-01-03, 07:02 PM
GRREAD maybe? (getint) will still require the operator to hit Enter.

Something like this?




(setq lst '())
(repeat 2
(setq lst (append (grread) lst))
)

Tom Beauford
2014-01-03, 07:11 PM
Hello Augi Members,

I have created some of simple Lisp programs, in some program I want to restrict user to input only single value (i.e. one or two or three digits) & as the digits are filled it takes "enter" command automatically.

Can anyone help me out of this.

Thanks in advance.

-Lalit
Without knowing how many digits how would it know when to "enter" automatically?

If you posted the code maybe we could offer a suggestion. Initget with getint would allow picking from a list with a right-click as an option or maybe a dialog box would help.

mailmaverick361505
2014-01-05, 08:06 AM
You can use INITGET function.

http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69da.htm

rkmcswain
2014-01-06, 02:59 PM
Hello Augi Members,
.... & as the digits are filled it takes "enter" command automatically.



You can use INITGET function.

INITGET does not fulfill the last part of OP's question

mailmaverick361505
2014-01-06, 05:10 PM
You are right rkmcswain.
Thanks for correcting me.

Stefan BMR
2014-01-06, 05:27 PM
Hello Augi Members,

I have created some of simple Lisp programs, in some program I want to restrict user to input only single value (i.e. one or two or three digits) & as the digits are filled it takes "enter" command automatically.

Can anyone help me out of this.

Thanks in advance.

-Lalit

Here (http://www.theswamp.org/index.php?topic=43877.msg491504#msg491504) you may find your answer.

Tom Beauford
2014-01-06, 07:18 PM
Here (http://www.theswamp.org/index.php?topic=43877.msg491504#msg491504) you may find your answer.

That's great if you know the user is keying in 5 digits, but the request was for "I want to restrict user to input only single value (i.e. one or two or three digits) & as the digits are filled it takes "enter" command automatically."

If "1", "11" and "111" are all valid entries how would the routine know to start working with either "1" or "11" and not wait for a third character? There has to be something to tell it ok we're going to run with this.

Stefan BMR
2014-01-06, 08:48 PM
Tom, the lisp in that link takes the number of digits as argument. I thought the user must know how many digits he need at a moment.


...I want to restrict user to input only single value ...
...If "1", "11" and "111" are all valid entries...
I must admit I didn't understand the question in that way, but you might be right.
In this case I'll wait OP's clarifications, because it might be easier to take another route, like picking the number from a popup menu (or something else).

jdiala
2014-01-08, 09:18 PM
Will this works for you?


(defun gr_key ( x / lst v)
(setq lst nil)
(repeat x
(while (not (= (car (setq v (grread t 15 0))) 2)))
(setq lst (cons (cadr v) lst))
(princ (chr (cadr v)))
)
(vl-list->string (reverse lst))
)



(gr_key 3) ;; will requires 3 characters
;; replace 3 with the number of characters needed

lalit_jangid
2014-01-23, 06:35 PM
(defun pipe_class_entry ()

(setq a12 (getstring "\nEnter Pipe Class - <A/B/C> :"))
(setq a2 (strcase a12))

(if (= a2 "A") (a_cls)
(if (= a2 "B") (b_cls)
(if (= a2 "C") (c_cls)
(progn
(alert "!!Invalid Entry, Please Try Again!!")
(princ)
(pipe_class_entry)
)
)))

)
--------------------------------------------------------------------------

problem 1 - with alphabets) I need that when the user presses the "a" / "b" or "c" key... it sets the value to variable & gets "enter" automatically


------------------------------------------------------------------------------

(defun pipe_length_entry ()
(if (or (<= l1 0) (= l1 nil)) (setq l1 3))
(princ "\nEnter Pipe Dimension in mtr - 1mtr to 6mtr only - Length <")
(princ l1)
(princ ">mtr:")
(setq l2 (getreal))
(if (= l2 nil) (setq l2 l1)
(if (<= l2 0) (progn (alert "!!Invalid Entry, Please Try Again!!") (pipe_length_entry) )
)
)
(setq l1 l2)
)

---------------------------------------------------------------------------------


problem 2 - with numerics) Here i want that whenever user presses keys between 1 to 6 it sets the value of the variable to given name & takes enter automatically...


HOpe this will help others to understand....

Please give suggestions for imporvement....

-Lalit

pbejse
2014-01-23, 10:55 PM
problem 1 - with alphabets) I need that when the user presses the "a" / "b" or "c" key... it sets the value to variable & gets "enter" automatically


(initget 1 "A B C")
(setq a2 (getkword "\nEnter Pipe Class - [A/B/C]:"))

(eval (cadr
(assoc a2
'(("A" (a_cls))
("B" (b_cls))
("C" (c_cls))
)))
)

or even

(eval (read (strcat "(" a2 "_cls)")))




problem 2 - with numerics) Here i want that whenever user presses keys between 1 to 6 it sets the value of the variable to given name & takes enter automatically...


(while
(not (progn
(initget 6)
(setq l2 (getint
(strcat
"\nEnter Pipe Dimension in mtr - 1mtr to 6mtr only - Length <"
(itoa l1)
"> mtr:")))
(cond
((null l2) (setq l2 l1))
((<= 1 l2 6)
(setq l2 l2
l1 l2))
(T (setq l2 nil)
(alert "!!Invalid Entry, Please Try Again!!"))
)
; L2 ;<-- This is progn termination
(print l2);<-- for Demo purposes
)
)
)

EDIT:

INITGET does not fulfill the last part of OP's question
Guess, I missed that part of the thread.. :lol:

Perhaps we can incorporate grread on the snippet above, Yes?