04-08-2013 04:34 PM
Apologies for my basic question.
I am experimenting with control arrays and so far am able to collect data in string controls that are inside control arrays. Works well. Naturally, none of these controls need callback functions.
Now I have need of some momentary command buttons in a control array as well. So my question is, should I use a single callback function for all of the button controls in that single array? And if so, how do I go about identifying which element in the control array called the function? From reading on the forums, it seems as if use of the callback data parameter might get me there.
Just wanted to ask before I get off track. Thanks!
Solved! Go to Solution.
04-09-2013 12:00 AM - edited 04-09-2013 12:01 AM
Yes, callbackData can be of help in such a situation, but if you can limit to switch on array index to discriminate what to do your button callback could be something on this line:
int CVICALLBACK BtnAttayCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int handle, index; switch (event) { case EVENT_COMMIT: handle = GetCtrlArrayFromResourceID (panel, control); GetCtrlArrayIndex (handle, panel, control, &index); switch (index) { // Your code here } } return 0; }
(No CVI install here so I cannot test it: double check the code but it should reasonably work)
04-09-2013 08:18 AM
Ahh, that works very nicely. It was the index function that I was missing. I didn't realize that GetCtrlArrayIndex could start with a UIR controlID to unpack the array index. Very handy function!
Here is my code:
int CVICALLBACK unitSetup (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int enabledArray; int SNArray; int index; char serialNumber[50]; switch (event) { case EVENT_LOST_FOCUS: // get the handles for the control arrays enabledArray = GetCtrlArrayFromResourceID(panel,ENABLE); SNArray = GetCtrlArrayFromResourceID(panel,SN); // get the index of the serial number control GetCtrlArrayIndex(SNArray, panel, control, &index); GetCtrlVal(panel,GetCtrlArrayItem(SNArray,index),serialNumber); // disable the enable checkbox if the serial number has not been setup if (*serialNumber == NULL) SetCtrlAttribute(panel,GetCtrlArrayItem(enabledArray,index),ATTR_DIMMED,TRUE); else SetCtrlAttribute(panel,GetCtrlArrayItem(enabledArray,index),ATTR_DIMMED,FALSE); break; } return 0; }