Hi sll,
I want it to remember the default character and enter it. But I think I'm making a mistake...
I am not getting the desired result.
Thanks in advance for the help friend.
(if (= ygY nil)(setq ygY "-"))
(setq ygY_t (getstring (strcat "\nReferans karakteri giriniz <"ygY"> :")))
(if (/= ygY_t "")(setq ygY ygY_t))
(setq ygY ygY_t)
Solved! Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
I would use this. *ygY* marks a globe variable
(if (= *ygY* nil) (setq *ygY* "-")) (setq ygY (getstring (strcat "\nReferans karakteri giriniz <"*ygY*"> :"))) (if (= ygY "") ; if Enter (setq ygY *ygY*) ; working var to pre-defined (setq *ygY* ygY)) ; saved value for the future usage.
Don't mind me but I see this construct used a lot and most of the time it looks to be the same code just copied and pasted over and over which tends to make code blocks/functions messy (-i.e. by not understanding which portions need to be copied or not changing comments or any number of reasons).
This method if used multiple times can be useful enough to build a library function from. I'll call the library function `getans'.
(defun getans ( iffalse / answer)
;; getans
;;
;; Prompt the user for an answer. Return 'nil' if no answer is supplied.
;;
;; EX:
;; Your answer please: 7
;; > "7"
(setq answer (getstring (strcat "\nYour answer please <" iffalse ">: ")))
;; ask the user for an anser
(if (eq answer "")
;; test to see if the anser is blank string
iffalse
;; if it is return 'iffalse' instead of ' "" '
answer
;; if its a real answer, return that instead.
);_ end if
);_ end defun
Now we can use it like:
;;; ...
(setq *ygY* (cond (*ygY*) ("-"))) ;; -Set global variable to a default if not already set.
;; if variable is set already, do not override that value.
(getans *ygY*) ;; -Prompt for answer from user and use a default if enduser
;; answers with enter -i.e. empty string.
;;; ...
The global variable portion can also be used to construct a generic function if it is a construct that is often repeated as well. I'll call it `set-if'.
(defun set-if ( var iffalse )
;; set-if
;; sets a variable to a value if the vaiable has NOT been set previously.
;; EX:
;; (set-if 'a 1)
(set var (cond ((eval var)) (iffalse)))
)
Now our code can be clean(er)--and we can focus on our comments (to make or life easier later)-.
;;; ...
(set-if '*ygY* "-") ;; -Set global variable to default ("-") if not already set.
(getans *ygY*) ;; -Prompt for answer from end user and use default stored
;; in global variable if end user answers with enter.
;;; ...
Another way.
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (= *ygY* nil) (setq *ygY* "-"))
(setq *ygY* (car (AH:getvalsm (list "Enter values " "Input new val or OK " 5 4 *ygY*))))
Can't find what you're looking for? Ask the community or share your knowledge.