dpSetFormat()

Sets the format of a DP element.

Synopsis

int dpSetFormat(string dp, langString dpFormat);

Parameters

Parameter Meaning
dp data point
dpFormat Formatting string for sprintf (for example, %f) in one or several languages.

Return Value

If OK the value is 0, in the event of an error -1.

Errors

Errors can be retrieved with getLastError(). An error message is issued in the event of incorrect DPs or missing arguments!

Description

The format can be changed with the CTRL function dpSetFormat().

No checks are made as to whether the format string entered matches the data type. The user must ensure that he/she enters the format correctly. If an incorrect format string (i.e. a string that does not match the data type) is entered, the output may not be the same as the original value when the CTRL function dpValToString() is used. The format for dpValToString() is converted via the internal use of sprintf(), you can therefore also use the formats of sprintf().

The use of "@" or another character used as DPCommentSeparator, will result in the data point comment being separated at the character. The characters after the first "@" character will be saved as data point format, the characters after the second "@" as the data point unit. Should the "@"character be needed, the separator character can be changed with the config entry [general] DpCommentSeparator.

Example

Sets the format of a data point to "%6.2f" (maximum number of digits 6).

main()
{
  int ret;
  ret= dpSetFormat("mld_float.","%6.2f");
}

Example

Sets the format of a data point in two different languages to %2d (maximum number of digits 2).

main()
{
  langString format;

  setLangString(format,0,"%2d");
  setLangString(format,1,"%2d");

  dpSetFormat("integer_1.",format);
}

The formatting string is used like in the sprintf function. For more different examples of using the format string, see chapter sprintf().

Assignment

Data point function, Waiting Control function

Availability

CTRL