Jump to content

Anything wrong with my code?Thanks.


Wwx95

Recommended Posts

(defun c:sbb(/a b)
 ((setq a 10 b 5)
   (if (> a b)
     (progn (princ a)
(setq a (+ a 5) b (+ b 6))
   ((princ a)(princ))
   ((princ b)(princ))
)
   )
 )
 )

Edited by SLW210
Added Code Tags
Link to comment
Share on other sites

(defun c:sbb ( / a b )
  ;( this isn't required
   (setq a 10 b 5)
   (if (> a b)
       (progn 
           (princ a)
           (setq a (+ a 5) b (+ b 6))
          ;( this isn't required
           (princ a)
          ;(princ) This can be replaced by one final (princ)
           this isn't required
          ;( this isn't required
           (princ b)
          ;(princ) This can be replaced by one final (princ)
           this isn't required
       ) ;; end progn
   ) ;; end if
   (princ) ;; This can replace the earlier (princ) expressions
   this isn't required
) ;; end defun

Link to comment
Share on other sites

Thanks Lee I thought I would give time for Wwx95 to have a go first. Nice touch the ;;defun I often do this for ;if's etc so you can keep count and make sure closing brackets.

Link to comment
Share on other sites

Thanks, I am new here, and I changed my code according to your code,is it like this?

 

(defun c:sbb (/ a b)
   (if (> a b)
       (progn 
           (princ a)
           (setq a (+ a 5) b (+ b 6))
       ) 
   )
) 

 

But how can I run it in CAD? Like this?

 

(setq a 10 b 5)
(sbb a b)

 

It doesn't work, and told me "error: no function definition: SBB"

Link to comment
Share on other sites

Thanks Lee I thought I would give time for Wwx95 to have a go first. Nice touch the ;;defun I often do this for ;if's etc so you can keep count and make sure closing brackets.

 

Thank you Al :)

 

But how can I run it in CAD? Like this?

(setq a 10 b 5)
(sbb a b)

It doesn't work, and told me "error: no function definition: SBB"

 

If you wish to evaluate the function with arguments, you will need to define it in the following way:

(defun sbb ( a b )
   (if (> a b)
       (progn
           (princ a)
           (setq a (+ a 5) b (+ b 6))
       )
   )
)

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