# Thread: Divide the value stored in system variable Distance

1. ## Divide the value stored in system variable Distance

I am writing a LISP code to give me the distance in decimal feet. Here is what I have so far:

Code:
```
;gives distance in decimal feet

(defun C:FE ()
(command "-units" "2" "3" "1" "3" "0.000" "n")
(command "DIST" pause pause)
(setq convert 12)
(/ DISTANCE convert)
(princ)
)```
The problem is in the division of the distance variable. When the distance command is used, it stores a read-only variable called "DISTANCE". All I want to do is divde this variable by 12 to give me feet. I am setting up a "convert" variable because I thought that AutoLISP wouldn't let me divde the variable DISTANCE by the number twelve directly, as in:

Code:
`(/ DISTANCE 12)`
I would appreciate any responses to this problem.

Blaine

2. ## Re: Divide the value stored in system variable Distance

Try this:
Code:
```(defun c:test (/ dec decft)
(setq des (getdist "\nEnter or pick your distance."))
(setq decft (/ des 12.0))
(print decft)
(princ)
)```

3. ## Re: Divide the value stored in system variable Distance

That worked. Thanks! However, I would like to know why what I had did not work. If I am going to learn AutoLISP, I need to be able to understand why what I had did not work.

Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.

Thanks,

Blaine

4. ## Re: Divide the value stored in system variable Distance

Originally Posted by blaine.67000
That worked. Thanks! However, I would like to know why what I had did not work. If I am going to learn AutoLISP, I need to be able to understand why what I had did not work.

Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.

Thanks,

Blaine
Are you referring to the DISTANCE system variable? You would need to get the value of the variable first before placing it within a function.
Code:
`(/ (getvar "DISTANCE") 12)`

5. ## Re: Divide the value stored in system variable Distance

Originally Posted by Opie

Are you referring to the DISTANCE system variable? You would need to get the value of the variable first before placing it within a function.
Yes, I am. And putting in the getvar function to retreive the DISTANCE system variable makes sense......I think.

6. ## Re: Divide the value stored in system variable Distance

Originally Posted by blaine.67000
Yes, I am. And putting in the getvar function to retreive the DISTANCE system variable makes sense......I think.
You would need to do this with any system variables.

7. ## Re: Divide the value stored in system variable Distance

Originally Posted by blaine.67000
Also, I believe that I am correct in my understanding that the portion of code after the defun is defining the local variables, but I don't understand why that is important or needed.
Opie,

Can you comment on my above question regarding local variables.

Thanks,

Blaine

8. ## Re: Divide the value stored in system variable Distance

Originally Posted by blaine.67000
Opie,

Can you comment on my above question regarding local variables.

Thanks,

Blaine
See this post. I know it doesn't relate to this actual routine, but it does explain the local variables a little.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•