AceRiddler Posted August 2, 2011 Share Posted August 2, 2011 Hi there, first post. I am new to AutoCad AutoLisping and i only began to read Mr. Rammage's tutorial. However, I'm testing some coding while i am reading it. Here is one thing i would like to get done; I would like to insert thoses 3 variables (a b c) into an alert message as in...confirming the information. (defun c:test1 ( / a b c) (setq a (getstring T "\nWhat is your full name?:")) (setq b (getstring T "\nName of the project?:")) (setq c (getreal "\nTime worked on it?(format exemple:2.5):")) (alert "(!a !b !c)") ; this part is not good. ) As you probably know, The alert message show me (!a !b !c), i tried many things and i will continue working on it while i'm waiting for an answer here. Let me know what needs to be done, Thank you all in advance. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 2, 2011 Share Posted August 2, 2011 Hi AceRiddler, Firstly, welcome to CADTutor - I hope you enjoy your time here. Consider the following function: (defun c:test1 ( / a b c ) (setq a (getstring T "\nWhat is your full name?:")) (setq b (getstring T "\nName of the project?:")) (setq c (getreal "\nTime worked on it?(format exemple:2.5):")) (alert (strcat a " " b " " (rtos c))) (princ) ) The exclaimation "!" prefix is only really to be used at the command-line. In LISP, functions will evaluate the arguments they are passed (depending upon function behaviour, e.g. 'setq' doesn't evaluate the first argument, but 'set' does). Note that since variable c is of data type 'real', it needs to be converted to a string before being used with either 'alert' or 'strcat'. Also, note that the current code will error if the user hits enter at the getreal prompt, since (rtos nil) will error. I haven't included error trapping in an attempt to keep the code close to what you posted, but you might consider adding an IF statement if using this in an application. Quote Link to comment Share on other sites More sharing options...
AceRiddler Posted August 2, 2011 Author Share Posted August 2, 2011 The exclaimation "!" prefix is only really to be used at the command-line. In LISP, functions will evaluate the arguments they are passed (depending upon function behaviour, e.g. 'setq' doesn't evaluate the first argument, but 'set' does). hmm yes that is what i thought. Note that since variable c is of data type 'real', it needs to be converted to a string before being used with either 'alert' or 'strcat'. Also, note that the current code will error if the user hits enter at the getreal prompt, since (rtos nil) will error. I haven't included error trapping in an attempt to keep the code close to what you posted, but you might consider adding an IF statement if using this in an application. First of all, thank you. I inserted a IF statement, but it is not really the one i want. right now the code looks like this ; (defun c:test1 ( / a b c ) (setq a (getstring T "\nWhat is your full name?:")) (setq b (getstring T "\nName of the project?:")) (setq c (getreal "\nTime worked on it?(format exemple:2.5):")) (if (= c nil) (setq c 0)) (alert (strcat a " " b " " (rtos c))) (princ) ) Right now if you skip the third prompt, you will get zero hour worked on the project. The IF statement i really want is a statement that says (if (= c nil) (then re-enter a value) I have been searching for the good code but didnt find so far. The other thing i would like to talk to you about is the alert message. I would like to make it jump a line between each variable instead of having them all in one line. ex: a b c I will still be working on it while i wait. Thank you very much, Lee Mac. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 2, 2011 Share Posted August 2, 2011 Consider this code: (defun c:test1 ( / a b c ) (setq a (getstring T "\nWhat is your full name?:")) (setq b (getstring T "\nName of the project?:")) (while (null (setq c (getreal "\nTime worked on it?(format exemple:2.5):")))) (alert (strcat a "\n" b "\n" (rtos c))) (princ) ) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted August 2, 2011 Share Posted August 2, 2011 You may also want to look into (initget) calls to force inputs. -David Quote Link to comment Share on other sites More sharing options...
AceRiddler Posted August 2, 2011 Author Share Posted August 2, 2011 Thank you david, i already tested a initget ! thanks again lee mac i'll post later on with new codings to the current lisp. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.