Admin Production ni-theme
Current Publication

Programming with Numeric Slide Controls

LabWindows/CVI

Programming with Numeric Slide Controls

This topic describes how to complete the following tasks programmatically.

Creating Numeric Slide Controls

Use NewCtrl to create a numeric slide control.

/* The controlTop and controlLeft parameters refer to the vertical and horizontal coordinates at which the control is placed. */

int numericSlideCtrl;

numericSlideCtrl = NewCtrl (panelHandle, CTRL_NUMERIC_LEVEL_HSLIDE_LS, "Numeric Slide Control", 20, 20);

Setting and Obtaining the Value of a Numeric Slide Control

Use SetCtrlVal to set the value of a numeric slide control.

SetCtrlVal (panelHandle, PANEL_NUMERICSLIDE, 7.8);

Use GetCtrlVal get the value of a numeric slide control.

double numericSlideVal;

GetCtrlVal (panelHandle, PANEL_NUMERICSLIDE, &numericSlideVal);
SetCtrlVal (panelHandle, PANEL_NUMERIC, numericSlideVal);

Specifying the Minimum and Maximum Values

Use SetCtrlAttribute with ATTR_MAX_VALUE and ATTR_MIN_VALUE to specify the minimum and maximum values of a numeric slide control.

SetCtrlAttribute(panelHandle, PANEL_NUMERICSLIDE, ATTR_MAX_VALUE, 20.0);
SetCtrlAttribute(panelHandle, PANEL_NUMERICSLIDE, ATTR_MIN_VALUE, -20.0);

Specifying the Numerical Format

Use SetCtrlAttribute with ATTR_FORMAT to specify the numerical format of a numeric slide control.

SetCtrlAttribute (panelHandle, PANEL_NUMERICSLIDE, ATTR_FORMAT, VAL_DECIMAL_FORMAT);

Customizing the Appearance

/* Set the color of the slider and tick style of the numeric slide control. */

SetCtrlAttribute (panelHandle, PANEL_NUMERICSLIDE, ATTR_SLIDER_COLOR, VAL_YELLOW);

SetCtrlAttribute (panelHandle, PANEL_NUMERICSLIDE, ATTR_TICK_STYLE, VAL_FULL_TICKS);

Showing the Radix

Use SetCtrlAttribute with ATTR_SHOW_RADIX or ATTR_CTRL_MODE to display the radix.

SetCtrlAttribute (panelHandle, PANEL_NUMERICSLIDE, ATTR_SHOW_RADIX, 1);

Adding and Customizing Fill Color

Use SetCtrlAttribute with ATTR_FILL_COLOR to add and customize the fill color of the numeric slide control.

SetCtrlAttribute (panelHandle, PANEL_NUMERICSLIDE, ATTR_FILL_COLOR, VAL_PANEL_GRAY);

Adding, Obtaining, and Removing a Color Ramp from a Numeric Slide Control

Use SetNumericColorRamp to add a color ramp to a numeric slide control.

/* The numberOfColors parameter refers to the number of entries in colorMapArray and blends colors together smoothly between specified data values. The interpolateColors parameter specifies how to assign colors to values that do not match the data values in colorMapArray.*/

ColorMapEntry colors[3];

colors[0].dataValue.valDouble = -5.0;
colors[0].color = VAL_YELLOW;
colors[1].dataValue.valDouble = 0.0;
colors[1].color = VAL_MAGENTA;
colors[2].dataValue.valDouble = 7.0;
colors[2].color = VAL_RED;

SetNumericColorRamp (panelHandle, PANEL_NUMERICSLIDE, colors, VAL_RED, 3, 1);

Use GetNumericColorRamp to obtain the values of a color ramp.

int hiColor;
int interp;
ColorMapEntry colorMap[10];

GetNumericColorRamp (panelHandle, PANEL_NUMERICSLIDE, colorMap, &hiColor, &interp);

The ATTR_NUM_COLOR_RAMP_VALUES attribute determines the number of ColorMapEntry structures in the color ramp.

int numColorValues;

GetCtrlAttribute (panelHandle, PANEL_NUMERICSLIDE, ATTR_NUM_COLOR_RAMP_VALUES, &numColorValues);

Call DiscardNumericColorRamp to remove a color ramp from a numeric slide control.

DiscardNumericColorRamp (panelHandle, PANEL_NUMERICSLIDE);

Using Range Checking

Use SetCtrlAttribute with ATTR_CHECK_RANGE to use range checking.

SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_CHECK_RANGE, VAL_COERCE);

Binding to a DataSocket Source

(Linux) Data binding is not supported.

Controls can have only one DataSocket connection. You must specify whether the access mode is READ mode or WRITE mode:

  • READ mode—The control gets data from the DataSocket source. In READ mode, the value of the numeric slide control is updated automatically when the value changes at the source.
  • WRITE mode—The control transfers data to the DataSocket source. In WRITE mode, the value at the DataSocket source is updated automatically when the value of the numeric slide control changes.

You must enable the DataSocket option in the Edit Installer dialog box Drivers & ComponentsDrivers & Components tab if your applications use data binding.

Binding to a DataSocket Source in the User Interface Editor

Complete the following steps to bind a network variable to a string control.

  1. In the Edit Numeric Slide dialog box, click the DataSocket Binding button.
  2. Click the browse button to the right of the Server text box in the DataSocket Binding dialog box.
  3. Select the network variable you want to bind and click the OK button.
  4. Select whether you want to read or write data in the Connection Type option.
  5. Click the OK button.

Binding to a DataSocket Source Programmatically

Use DSBindCtrl to bind a numeric slide control to a DataSocket source.

HRESULT dsError;
DSHandle dsHandle;

DSBindCtrl (panelHandle, PANEL_NUMERICSLIDE, "opc://localhost/National Instruments.OPCDemo/MotorRPMSensor", VAL_DS_READ, &dsHandle, &dsError);

Use DSUnbind to disconnect the numeric control from the DataSocket source.

DSUnbind (panelHandle, PANEL_NUMERICSLIDE, &dsError);

Related Topics

Programming with Controls

Numeric Slide Control Functions