PDA

View Full Version : Default Selection...


BoKirra
2008-12-11, 03:00 AM
Hi ALL,

I have defined 2 conditions A & B for a routine.
By using initget & getkword it works fine.
But now I'd like to do a little bit more:
If the user hit the "ENTER" key, it will set to condition A automatically.

Your helps would be much appreciated.

Opie
2008-12-11, 04:11 AM
Then do your conditional statement for condition B. If it isn't B, then set it to A.

rkmcswain
2008-12-11, 04:15 AM
Test for the return value when ENTER is pressed (in this case, nil) and if you get this, then set your variable to whatever the "default" value is.


;;;Example
(initget "A B")
(setq res (getkword "Choose between [Apple/<Banana>]: "))
(if (not res)(setq res "B"))

BoKirra
2008-12-11, 04:49 AM
Test for the return value when ENTER is pressed (in this case, nil) and if you get this, then set your variable to whatever the "default" value is.


;;;Example
(initget "A B")
(setq res (getkword "Choose between [Apple/<Banana>]: "))
(if (not res)(setq res "B"))


I didn't remove 1 from the statment:
(initget 1 "A B")
Many thanks to you & Opie.:lol:

BoKirra
2008-12-16, 02:36 AM
Test for the return value when ENTER is pressed (in this case, nil) and if you get this, then set your variable to whatever the "default" value is.


;;;Example
(initget "A B")
(setq res (getkword "Choose between [Apple/<Banana>]: "))
(if (not res)(setq res "B"))


One more question:
What if there is another condition "C"?

Will the following work?
(initget "A B C")
(setq res (getkword "Choose between [Apple/<Banana>/Currant]: "))
(if (not res)(setq res "B"))

Thanks.

'gile'
2008-12-16, 08:05 AM
Hi,

I'd rather write the complete keywords in the initget list (with uppercase shortcuts).

(initget "Apple Banana Currant")
(or
(setq res (getkword "Choose between [Apple/Banana/Currant] <B>: "))
(setq res "Banana")
)

BoKirra
2008-12-16, 11:11 AM
Hi,

I'd rather write the complete keywords in the initget list (with uppercase shortcuts).

(initget "Apple Banana Currant")
(or
(setq res (getkword "Choose between [Apple/Banana/Currant] <B>: "))
(setq res "Banana")
)

A nice tip!
Thanks again.

rkmcswain
2008-12-16, 02:15 PM
Here is another way. This remembers the last choice and makes it the default. Of course, if you want it to remember the last choice between commands or even between drawing sessions - you will have to save the last choice outside this code... and modify the first line upon the launch of this code... (The repeat and alert functions are only in this code below to illustrate what is going on...)


(setq str "[Apple/<Banana>/Currant]" def "Banana")
(repeat 8
(initget "Apple Banana Currant")
(setq res (getkword (strcat "Choose between " str ": ")))
(cond ((eq res "Apple")(setq str "[<Apple>/Banana/Currant]" def res))
((eq res "Banana")(setq str "[Apple/<Banana>/Currant]" def res))
((eq res "Currant")(setq str "[Apple/Banana/<Currant>]" def res))
((not res)(setq res def))
)
(alert res)
)

BoKirra
2008-12-17, 02:35 AM
Here is another way. This remembers the last choice and makes it the default. Of course, if you want it to remember the last choice between commands or even between drawing sessions - you will have to save the last choice outside this code... and modify the first line upon the launch of this code... (The repeat and alert functions are only in this code below to illustrate what is going on...)


(setq str "[Apple/<Banana>/Currant]" def "Banana")
(repeat 8
(initget "Apple Banana Currant")
(setq res (getkword (strcat "Choose between " str ": ")))
(cond ((eq res "Apple")(setq str "[<Apple>/Banana/Currant]" def res))
((eq res "Banana")(setq str "[Apple/<Banana>/Currant]" def res))
((eq res "Currant")(setq str "[Apple/Banana/<Currant>]" def res))
((not res)(setq res def))
)
(alert res)
)


Thanks. You're the big man.
I can't feel that I'll graduate from LISP kindy.