paCfgReadValueDflt()

The function returns either the value of the found entry or the default value.

Synopsis

<type> paCfgReadValueDflt(string filename, string section, string key, <type> dfltValue[, bool & isDflt [,string host]]);

Parameters

Parameter Description
filename The file name (including the file path) of the config file, for example: "C:\WinCC_OA_Proj\MyProject\config\config" or with using getPath():getPath(CONFIG_REL_PATH, "config")
section The section of the config file, for example, "general"
key The config entry whose value will be read, for example, "langs"
dfltValue The default value.
isDflt If the parameter is false (FALSE has been returned), the entry has been found. If the parameter is true, the entry has not been found and the default value applies.
host If this parameter has been specified, only the entries with this host, for example, $host1 will be read. If an entry is empty "", only entries without a host name will be read. If no host parameter has been specified, no host entries will be read.

Return value

The found config entry.

Error

Missing or wrong arguments

Description

The function reads with a specified default value if the config entry does not exist. Therefore, the function returns either the value of the found entry or the default value.

Example

You have to include the CtrlPv2Admin DLL into the general part of the code (to be able to use the paCfgInsertValue function) as follows: #uses "CtrlPv2Admin"

The following example reads the value of the langs entry if it can be found. If the entry is not found, the specified default value will be shown.

main()
{
  string val;
  string filename = "c:/WinCC_OA_Proj/test/config/config";
  string section = "general";
  string dfltValue = "Sprache";
  bool isDflt;
  val = paCfgReadValueDflt(filename,section,
  "langs",dfltValue,isDflt);
  if (!isDflt)
  {
    DebugN("Return value is:",val);
  }
  else
  {
    DebugN("Default value is:",dfltValue);
  }
}

Note that the maximum number of characters in a line of the configuration file is restricted to 511 characters (see also Configuration file). If this number is exceeded, -1 is returned.

Assignment

Project administration functions

Availability

CTRL