Optimizing code

Started by vladimirzm · 2009-03-02 23:29 UTC · 3 replies · SMF topic #615

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?
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....
Also, have a look at this code, to loop through all the controls on a form..
{2}
Of course change the "FontSize" to something else & don't SaveAs the project to anther files.
thnx i'll try