Jump to content

inserting variable in alert message


AceRiddler

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

Thank you david, i already tested a initget !

thanks again lee mac

 

i'll post later on with new codings to the current lisp.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...