Admin Production ni-theme
Current Publication

Programming with Ring Slide Controls

LabWindows/CVI

Programming with Ring Slide Controls

This topic describes how to complete the following tasks programmatically.

Creating a Ring Slide Control

Use the NewCtrl function to create a ring slide control. The ring slide control is empty initially. To insert items, call InsertListItem.

int ringSlide;

ringSlide = NewCtrl (panelHandle, CTRL_RING_POINTER_VSLIDE_LS, "Ring Slide", 30, 110);
InsertListItem (panelHandle, ringSlide, -1, "Rising Clock Edge", 0);
InsertListItem (panelHandle, ringSlide, -1, "Falling Clock Edge", 1);
InsertListItem (panelHandle, ringSlide, -1, "Both Clock Edges", 2);
SetCtrlAttribute (panelHandle, ringSlide, ATTR_HEIGHT, 120);

Setting the Active Item

You can set the active item based on ring item index or the value of the ring item.

int val, index;

GetCtrlVal (panelHandle, PANEL_NUMERIC, &val);
SetCtrlVal (panelHandle, ringSlide, val); // Based on value
GetCtrlVal (panelHandle, PANEL_NUMERIC, &index);
SetCtrlIndex (panelHandle, ringSlide, index); // Based on index

Deleting and Replacing Items in the Ring Slide Control

Call DeleteListItem to delete a specified number of items from the ring control.

int idxToDel, numToDel;

GetCtrlVal (panelHandle, PANEL_INDEXDEL, &idxToDel);
GetCtrlVal (panelHandle, PANEL_DELITEMS, &numToDel);
DeleteListItem (panelHandle, PANEL_RINGSLIDE, idxToDel, numToDel);

Call ClearListCtrl to delete all of the items in the ring control.

ClearListCtrl (panelHandle, PANEL_RINGSLIDE);

Call ReplaceListItem to substitute one list item with another one you specify.

ReplaceListItem (panelHandle, PANEL_RINGSLIDE, 2, "Both Clock Edges", 2);

Obtaining the Number of Items

int count;

GetNumListItems (panelHandle, PANEL_RINGSLIDE, &count);

Obtaining the Value and Index of the Currently Selected Item

int itemIndex, itemValue;

GetCtrlIndex (panelHandle, PANEL_RING, &itemIndex);
SetCtrlVal (panelHandle, PANEL_DEVINDEX, itemIndex);

GetCtrlVal (panelHandle, PANEL_RING, &itemValue);
SetCtrlVal (panelHandle, PANEL_VALINDEX, itemValue);

Associating the Data Type of the Ring Control with Values

The data type for a ring slide control determines the type of data you can use for the value of ring items. You must match the values you pass to some of the functions with the data type of the control. The pointers you pass to functions that return values must also be compatible with the current data type of the control.

To set the data type, use the ATTR_DATA_TYPE attribute.

SetCtrlAttribute (panelHandle, dataRingSlide, ATTR_DATA_TYPE, VAL_STRING);

Because the data type of the values in the ring slide control is a character array in this instance, you must make sure the values you pass to the ring slide control and pointers to obtain values from the ring slide control are also string values.

InsertListItem (panelHandle, dataRingSlide, 0, "Int", "4 byte integer");
InsertListItem (panelHandle, dataRingSlide, -1, "Char", "Single byte character");
InsertListItem (panelHandle, dataRingSlide, -1, "Double", "8 byte floating point value");
InsertListItem (panelHandle, dataRingSlide, -1, "String", "Character array");

Converting between Label, Value, and Indices of Items

You can convert between labels, values, and indices of ring slide control items.

int index, ringLabelLen, ringIdx, ringValue;
char *ringLabel = NULL;

// Convert index to value
GetCtrlIndex (panelHandle, PANEL_RINGSLIDE, &ringIdx);
GetValueFromIndex (panelHandle, PANEL_RINGSLIDE, ringIdx, &ringValue);
SetCtrlVal (panelHandle, PANEL_VALUE, ringValue);

// Convert index to label
GetLabelLengthFromIndex (panelHandle, PANEL_RINGSLIDE, ringIdx, &ringLabelLen);

GetLabelLength appends a NULL byte to the end of the text string, so you must make the buffer 1 byte larger than the value obtained from GetLabelLengthFromIndex.

ringLabel = malloc (sizeof(char) * (ringLabelLen + 1));
GetLabelFromIndex (panelHandle, PANEL_RINGSLIDE, ringIdx, ringLabel);
SetCtrlVal (panelHandle, PANEL_LABEL, ringLabel);

// Convert value to index
GetIndexFromValue (panelHandle, PANEL_RINGSLIDE, &index, ringValue);
SetCtrlVal (panelHandle, PANEL_INDEX, index);

Setting the Default Item

Specify the default item by index or by value. If you call the following example code after the call to LoadPanel, you must call DefaultCtrl to update the user interface.

// By index
SetCtrlAttribute (panelHandle, PANEL_RINGSLIDE, ATTR_DFLT_INDEX, 2);
DefaultCtrl (panelHandle, PANEL_RINGSLIDE);

// By value
SetCtrlAttribute (panelHandle, PANEL_RINGSLIDE, ATTR_DFLT_VALUE, 1);
DefaultCtrl (panelHandle, PANEL_RINGSLIDE);

Customizing the Slider Appearance

SetCtrlAttribute (panelHandle, ringSlide, ATTR_SLIDER_COLOR, VAL_BLACK);
SetCtrlAttribute (panelHandle, ringSlide, ATTR_SLIDER_HEIGHT, 15);
SetCtrlAttribute (panelHandle, ringSlide, ATTR_SLIDER_WIDTH, 25);

Customizing the Fill Color

SetCtrlAttribute (panelHandle, ringSlide, ATTR_FILL_OPTION, VAL_BOTTOM_FILL);
SetCtrlAttribute (panelHandle, ringSlide, ATTR_FILL_COLOR, VAL_WHITE);
SetCtrlAttribute (panelHandle, ringSlide, ATTR_FILL_HOUSING_COLOR, VAL_DK_GRAY);

Removing Check Marks from the Ring Control

SetCtrlAttribute (panelHandle, PANEL_RINGSLIDE, ATTR_DISABLE_CHECK_MARK, 0);

Setting Text Styles for Ring Items

SetCtrlAttribute (panelHandle, ringSlide, ATTR_TEXT_BOLD, 1);
SetCtrlAttribute (panelHandle, ringSlide, ATTR_TEXT_FONT, "Times New Roman");

Related Topics

Programming with Controls

Ring Slide Control Functions