Author Topic: Any way to improve coding ?  (Read 2756 times)

0 Members and 1 Guest are viewing this topic.

kruuger

  • Swamp Rat
  • Posts: 635
Any way to improve coding ?
« on: September 04, 2012, 07:11:32 AM »
hello,

please see attached code and image below.
is there any better way to improve coding for this dialog ?
especially for action_tile "IMx", function _UpdateImageButton and variable *im *or *by.

is code a little bit clear for you, how all things work together or definitely need rework ?

thank you
kruuger

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Any way to improve coding ?
« Reply #1 on: September 04, 2012, 08:03:11 AM »
usually, I wrap this code in 'foreach

Code - Auto/Visual Lisp: [Select]
  1.       (action_tile "IM1" "(setq *im (cd:LST_ReplaceItem 0 *im (abs (- 1 (nth 0 *im)))) *or (abs (- 1 (nth 0 *im))) *by 0) (_UpdateImageButton)")
  2.       (action_tile "IM2" "(setq *im (cd:LST_ReplaceItem 2 *im (abs (- 1 (nth 2 *im)))) *or (abs (- 1 (nth 2 *im))) *by 1) (_UpdateImageButton)")
  3.       (action_tile "IM3" "(setq *im (cd:LST_ReplaceItem 4 *im (abs (- 1 (nth 4 *im)))) *or (abs (- 1 (nth 4 *im))) *by 2) (_UpdateImageButton)")

kruuger

  • Swamp Rat
  • Posts: 635
Re: Any way to improve coding ?
« Reply #2 on: September 04, 2012, 08:41:15 AM »
thanks Evgeniy

it seems that it should work but error ?
Code - Auto/Visual Lisp: [Select]
  1.       (foreach % (list 0 1 2)
  2.         (action_tile (strcat "IM" (itoa (1+ %)))
  3.           (vl-prin1-to-string
  4.             (quote
  5.               (progn
  6.                 (setq *im (cd:LST_ReplaceItem (* 2 %) *im (abs (- 1 (nth (* 2 %) *im))))
  7.                       *or (abs (- 1 (nth (* 2 %) *im)))
  8.                       *by %
  9.                 )
  10.                 (_UpdateImageButton)
  11.               )
  12.             )
  13.           )
  14.         )
  15.       )

kruuger

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Any way to improve coding ?
« Reply #3 on: September 04, 2012, 09:13:57 AM »
The symbol '%' won't be evaluated inside the quoted expression.

kruuger

  • Swamp Rat
  • Posts: 635
Re: Any way to improve coding ?
« Reply #4 on: September 05, 2012, 05:22:28 PM »
thanks Lee. is there any way to fix this or need to play with strcat
Code - Auto/Visual Lisp: [Select]
  1.       (foreach % (list 0 1 2)
  2.         (action_tile (strcat "IM" (itoa (1+ %)))
  3.           (strcat
  4.             "(setq *im (cd:LST_ReplaceItem (* 2 " (itoa %) ") *im (abs (- 1 (nth (* 2 " (itoa %) ") *im))))"
  5.             "      *or (abs (- 1 (nth (* 2 " (itoa %) ") *im)))"
  6.             "      *by " (itoa %) ")"
  7.             "(_UpdateImageButton)"
  8.           )
  9.         )
  10.       )
kruuger

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Any way to improve coding ?
« Reply #5 on: September 05, 2012, 07:09:21 PM »
Maybe not better, but find attached my thoughts on a different way to code it.  :-)

kruuger

  • Swamp Rat
  • Posts: 635
Re: Any way to improve coding ?
« Reply #6 on: September 06, 2012, 03:43:36 PM »
Maybe not better, but find attached my thoughts on a different way to code it.  :-)
thanks Lee. it is good to see the different approach  :-)

kruuger

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Any way to improve coding ?
« Reply #7 on: September 06, 2012, 06:42:09 PM »
You're welcome kruuger, hope it helps  :-)