Associate user input string to specific variable

Associate user input string to specific variable

Rob_Durham
Enthusiast Enthusiast
1,018 Views
3 Replies
Message 1 of 4

Associate user input string to specific variable

Rob_Durham
Enthusiast
Enthusiast

Hi there,

 

I have defined a value to each date of the year

 

for example 

 

(Setq 21/06/16 (441294067.896324))
(Setq 22/06/16 (443874734.960046))

 

The lisp routine prompts the user to enter a date in the format (dd/mm/yy)

 

(setq date (getstring "Enter date (dd/mm/yy) "))

 

How do I associate the string entered by the user to the specific value associated with that particular date in my list of variables?

 

For example the user enters: 21/06/16, how do I get it to use the value 441294067.896324 for use in other commands?

 

Thanks

0 Likes
1,019 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

I would suggest something like this...

 

(defun c:test nil

  (setq dtelst '(("21/06/16" . 441294067.896324)
		 ("22/06/16" . 443874734.960046))
	dte (getstring "\nSet date: "))

  (cdr (assoc dte dtelst))
)

 

 

Or your way using variables...

 

> (setq 21/06/16 441294067.896324)
4.41294e+008

> (eval (read (getstring)))
> 21/06/16
4.41294e+008

 

Message 3 of 4

Rob_Durham
Enthusiast
Enthusiast

Your first method worked perfectly.

 

Thank you

0 Likes
Message 4 of 4

scot-65
Advisor
Advisor
Did you notice the variable created by BeeKee
did not begin with a number?
And the dotted-pair is quoted (meaning it is a STRING)
when the first character is a number?

.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes