Author Topic: Need Help With IF Statement  (Read 3429 times)

0 Members and 1 Guest are viewing this topic.

Murphy

  • Guest
Need Help With IF Statement
« on: October 21, 2005, 09:57:49 AM »
Yep, new to LISP.
Cannot get this to pass the VLISP testing.

I need to check USERR1, if it's 0 then ask for a number from the user, set USERR1 to that number and continue.
Here is the code, it is saying too many arguments:
Code: [Select]
  (IF VARR = 0
     (SETQ SCL
       (getreal (strcat "\nScale "))
(SETVAR "USERR1" SCL)
(SETQ VARR (GETVAR "USERR1")
))

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Re: Need Help With IF Statement
« Reply #1 on: October 21, 2005, 10:10:55 AM »
Comparisons in lisp are somewhat backwards....
Code: [Select]
(if (= VARR 0)
  (progn ;;use this if more than 1 line of code is needed
    (setq SCL (getreal "\nScale: "))
    (setvar "USERR1" SCL)
    (setq VARR (getvar "USERR1"))
   )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need Help With IF Statement
« Reply #2 on: October 21, 2005, 10:20:06 AM »
Code: [Select]
(IF VARR = 0  ....

Try

Code: [Select]
(IF (= VAR 0 ) ....
or

Code: [Select]
(IF (zerop (getvar "USERR1")) ....
or

Code: [Select]
(IF (=  0 (getvar "USERR1)) ....

It's a bit difficult trying to determine what you want

Is this it .. or DO you want VARR to hold the Value, or both ..

Code: [Select]
(if (zerop (getvar "USERR1"))
  (progn (setq SCL (getreal "\nNew Scale : "))
         (setvar "USERR1" SCL)        
  )  
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need Help With IF Statement
« Reply #3 on: October 21, 2005, 10:20:41 AM »
beaten to the punch .. again :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Murphy

  • Guest
Re: Need Help With IF Statement
« Reply #4 on: October 21, 2005, 10:29:55 AM »
OK. Found this code on FreeCadApps and am trying to modify to get scale for lengths of 'wings'.
It gives me this error
Code: [Select]
Command: cct
; error: bad function: 0.165

I am trying to multiply the VARR by 0.165 to set the length of the wings.

Code: [Select]
;*** CCT.LSP
;*** Written by gorgeous Rob from Australia who came to help us for a while
;
;
; Disclaimer:
; Permission to use, copy, modify, and distribute this software
; for any purpose and without fee is hereby granted, provided
; that the above copyright notice appears in all copies and
; that both that copyright notice and the limited warranty and
; restricted rights notice below appear in all supporting
; documentation.
;
; THIS PROGRAM IS PROVIDED "AS IS" AND WITH ALL FAULTS.  THE AUTHOR
; SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR
; FITNESS FOR A PARTICULAR USE.  THE AUTHOR ALSO DOES NOT WARRANT THAT
; THE OPERATION OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
;
; Routine for drawing circuit lines between light fittings consisting of 45 degree line from
; first point, straight line between and 45 degree line to second point
; If routine gives a straight line, try zooming in closer
;
;*** Function  CCT



(DEFUN C:CCT (/ A B C D LEN ANG SCL VARR WNG)
   (SETQ VARR (GETVAR "USERR1")
 (if (= VARR 0)
  (progn ;;use this if more than 1 line of code is needed
    (setq SCL (getreal "\nScale: "))
    (setvar "USERR1" SCL)
    (setq VARR (getvar "USERR1"))
   )
)
   (SETQ WNG (0.165 VARR))
   (SETQ A (GETPOINT "1ST POINT: "))
   (SETQ B (GETPOINT A "2ND POINT: "))
   (SETQ LEN (DISTANCE A B))
   (SETQ ANG (ANGLE A B))
   (SETQ C (POLAR A (+ ANG 0.7854) WNG))
   (SETQ D (POLAR B (+ ANG 2.356) WNG))
   (COMMAND "PLINE" A C D B "")
)


Murphy

  • Guest
Re: Need Help With IF Statement
« Reply #5 on: October 21, 2005, 10:52:20 AM »
Alright. I found the problem.
Gosh-darned parentheses   :realmad:
Code: [Select]
(SETQ VARR (GETVAR "USERR1")
Should be
Code: [Select]
(SETQ VARR (GETVAR "USERR1"))

Thank you Jeff and Kerry for your help!!  :kewl:

hudster

  • Gator
  • Posts: 2848
Re: Need Help With IF Statement
« Reply #6 on: October 21, 2005, 11:02:30 AM »
if your trying to multiply varr by 0.165 you are missing the * in the following code

Code: [Select]
(SETQ WNG (0.165 VARR))
should this be

Code: [Select]
(SETQ WNG (* 0.165 VARR))
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Re: Need Help With IF Statement
« Reply #7 on: October 21, 2005, 11:03:51 AM »
You're welcome!
Btw, this line: (SETQ WNG (0.165 VARR))
should be: (SETQ WNG (* 0.165 VARR))


Sorry, Kerry... :D Heh, now I was beat out by Hudster.....

Murphy

  • Guest
Re: Need Help With IF Statement
« Reply #8 on: October 21, 2005, 11:21:40 AM »
You are right. I forgot to post that correction.
Had to look through Cab's PLine2Cloud routine to figure out the syntax for multiplying.
Now I know why I like VBA.  :roll:

Dommy2Hotty

  • Swamp Rat
  • Posts: 1128
Re: Need Help With IF Statement
« Reply #9 on: October 21, 2005, 11:24:33 AM »
I can't get past the header:

;***   CCT.LSP
;***   Written by gorgeous Rob from Australia who came to help us for a while

deegeecees

  • Guest
Re: Need Help With IF Statement
« Reply #10 on: October 21, 2005, 01:11:58 PM »
Sounds like WWE got hold of him.  :-)