Admin Production ni-theme
Current Publication

Programming with Control Arrays

LabWindows/CVI

Programming with Control Arrays

Use the Control Array functions to create and interact with the array of user interface controls programmatically.

Obtaining a Handle

NewCtrlArray creates a new array of user interface controls and returns a handle that you can use to reference the array in subsequent operations. Use the panelHandle parameter to specify a panel on which the controls you want use in the control array are located. The control array also belongs to the panel handle that you pass to the NewCtrlArray function.

If you create an array of controls interactively in the User Interface BrowserUser Interface Browser, obtain the control array handle using the GetCtrlArrayFromResourceID function as demonstrated in the following code.

ctrlarray = GetCtrlArrayFromResourceID (panelHandle, CTRLARRAY);

Performing Batch Operations on Controls

Use functions that operate on all controls in the array, such as MoveCtrlArray, SetCtrlArrayVal, and SetCtrlArrayAttribute to perform batch operations on all controls in the array. For example, assuming ctrlArray is an array of LED controls, the following code turns on all of the LED controls in the array.

SetCtrlArrayVal(ctrlArray, 1);

Iterating through Controls at Run-Time

Use GetNumCtrlArrayItems to get the number of items in the control array. Use GetCtrlArrayItem to operate on a control at the specified index in the array. Using these two functions, you can iterate through the controls in the array to perform some action at run-time. Assuming that ctrlArray is an array of LED controls, the following example code iterates through the control array and turns on LED controls with odd array indices and turns off LED controls with even array indices.

GetNumCtrlArrayItems(ctrlArray, &count);
for (i=0; i<count; i++)

SetCtrlVal(panelHandle, GetCtrlArrayItem(ctrlArray, i), i%2);