Optimizing code

Started by vladimirzm, March 02, 2009, 03:29:25 PM

Previous topic - Next topic

vladimirzm

Hi
i have some lines like:
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox1 (cdr (assoc 0 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox2 (cdr (assoc 1 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox3 (cdr (assoc 2 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox4 (cdr (assoc 3 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox5 (cdr (assoc 4 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox6 (cdr (assoc 5 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox7 (cdr (assoc 6 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox8 (cdr (assoc 7 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox9 (cdr (assoc 8 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox10 (cdr (assoc 9 *mtmm-sslst*)))
  (dcl_Control_SetValue tmm-modeless_Form1_CheckBox11 (cdr (assoc 10 *mtmm-sslst*)))


this happens "OnInitialize" but then their values change so is a bit confussing type or even copy lines and change just two or three words and i made my own version:

(defun setbox (box int)
  (eval
    (read (strcat
    "(dcl_Control_SetValue tmm-modeless_Form1_Check"
    box ; for example "Box1"
    " (cdr (assoc "
    (itoa int) ; for example 1
    " *mtmm-sslst*)))"
   )
    )
  )
)


then (setbox "Box1" 1) = (dcl_Control_SetValue tmm-modeless_Form1_CheckBox1 (cdr (assoc 0 *mtmm-sslst*)))
even i can use foreach or mapcar for several items
it works but it shows me an error to: "NIL value not allowed" but it works.
Where is the rigth way?

BazzaCAD

You should be able to call the control names as strings. Try something like this:

(defun setbox (box int) 
  (dcl_Control_SetValue "tmm-modeless" "Form1" box (cdr (assoc int *mtmm-sslst*)))
)


(setbox "CheckBox1" 1)
Untested....
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

BazzaCAD

Also, have a look at this code, to loop through all the controls on a form..
http://www.opendcl.com/HelpFiles/index.php?lang=ENU&page=Advanced/Tips.htm
Of course change the "FontSize" to something else & don't SaveAs the project to anther files.
a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

vladimirzm