Condensing Code for Similar Functions
Ken
CheckBox Series,pos={151,70},size={64,14},proc=CheckProc,title="Series 1"
CheckBox Series,fStyle=17,variable= V
Function CheckProc(ctrlName, x) : CheckBoxControl
String ctrlName
Variable x
Another_function ()
End
So for example,
CheckBox Series_1,pos={151,70},size={64,14},proc=CheckProc_1,title="Series 1"
CheckBox Series_1,fStyle=17,variable= V_1
CheckBox Series_2,pos={151,95},size={64,14},proc=CheckProc_2,title="Series 2"
CheckBox Series_2,fStyle=17,variable= V_2
...
Function CheckProc_1(ctrlName, x) : CheckBoxControl
String ctrlName
Variable x
Another_function ()
End
Function CheckProc_2(ctrlName, x) : CheckBoxControl
String ctrlName
Variable x
Another_function ()
End
...
Many thanks!
STRUCT WMCheckboxAction &cba
switch( cba.eventCode )
case 2: // mouse up
Variable checked = cba.checked
strswitch(cba.ctrlName)
case "checkbox01":
// do checkbox01 actions
...
break
case "checkbox02":
// do checkbox02 actions
...
break
...
endswitch
break
case -1: // control being killed
break
endswitch
return 0
End
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
May 26, 2011 at 09:39 am - Permalink
May 31, 2011 at 09:44 am - Permalink
It makes a panel and condenses the creation of as many checkboxes as you like in a loop. Checkboxes and their control variables share common base names with a numeric extension.
In this example a single, very simple example procedure is called when the boxes are "clicked".
String sCB_Name
String sCB_BaseName = "CB_check"
String sCB_VariableName
String sCB_VariableBaseName = "vCBval"
String sDataFolder = "root:CheckBoxPanel"
String sProcName
String sProcBaseName = "cbProc"
Variable vCB_Position = 0
Variable vIndex = 0
NewDataFolder/O $sDataFolder //for checkbox variables
PauseUpdate; Silent 1 // building window...
NewPanel /W=(403,135,777,485)
Do
sCB_Name = sCB_BaseName + num2str(vIndex)
sCB_VariableName = sDataFolder + ":" + sCB_VariableBaseName + num2str(vIndex)
sProcName = sProcBaseName //+ num2str(vIndex) //use this if there's a proc for each checkbox
vCB_Position += 20 //y position of checkbox
Variable/G $(sCB_VariableName) = 1 //create global variable for each checkbox, initial value is checked
CheckBox $sCB_Name,pos={1,vCB_Position},size={40,14},variable= $sCB_VariableName
CheckBox $sCB_Name,title=sCB_Name, proc=$sProcName
vIndex += 1
While(vIndex<5)
End
Function cbProc(cba) : CheckBoxControl
STRUCT WMCheckboxAction &cba
String sCtrlName = cba.ctrlName
switch( cba.eventCode )
case 2: // mouse up
print cba.ctrlName
print cba.checked
break
case -1: // control being killed
break
endswitch
return 0
End
May 31, 2011 at 01:57 pm - Permalink
variable x
...
end
Function check02(x)
variable x
...
end
Function CheckProc(cba) : CheckBoxControl
STRUCT WMCheckboxAction &cba
variable x = 2
switch( cba.eventCode )
case 2: // mouse up
Variable checked = cba.checked
FUNCREF myprotofunc f = $cba.ctrlName
f(x)
break
case -1: // control being killed
break
endswitch
return 0
End
(EDIT)
Oh. My apologies. Now I understand. You want to have a code create a panel for you. For that, use the code by jtigor, however the procedure name can just be CheckProc with the above code to automatically call depending on check box name.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
May 31, 2011 at 03:18 pm - Permalink
You *do* have to have a different action procedure for different types of controls because they each carry different kinds of information.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
June 1, 2011 at 09:30 am - Permalink
June 10, 2011 at 10:19 am - Permalink