WriteSectINI

(System Library)

Description: This subroutine writes an entire section to a configuration file or a buffer containing one and returns its error code. Will not access .Startup or .Dynamic files.
Access to configuration files is not reliable unless the caller holds the working copy lock. Acquiring the lock is a steady-state only operation, and therefore similar legacy operations that used script-mode access to these files are deprecated or no longer supported (see comments)
Returns: Numeric
Usage: Script Only.
Function Groups: File I/O
Related to: CheckFileExist | CheckPathExist | Edit | Folder | ReadINI | ReadSectINI | WriteINI
Format: System.WriteSectINI(File, Section, VarList [, UseBuff])
Parameters:  
File   
Required. Any text expression giving the absolute path and file name of the Settings file or the name of the buffer containing its contents.
Section   
Required. Any text expression giving the name of the section in the file. This should not include the square brackets delimiting the section.
VarList   
Required. A 2 dimensional array containing the variables and their values to write to the file. The first row, VarList[0][N], contains the variable names, while the second row, VarList[1][N] contains their values.
UseBuff   
An optional parameter that is any logical expression. If true (non-0) the value of File must be a pointer to a buffer, if false (0) it is a file that is to be used. The default used if this parameter is omitted is false.
Comments:

WriteSectINI is a subroutine, and as such it needs to return quickly. It therefore cannot wait for a lock. For developers the lock means that access to VTScada working copy files, both reading and writing, should not be done without having the lock. The lock is across all applications and system layer VTScada code. The lock prevents two different piece of code from changing the same code such that one piece of code sees inconsistent data while the other code is in the middle of changing it.

This module is a member of the System Library, and must therefore be prefaced by \System. as shown in the "Format" section.

If your application predates version 11.2, use the backslash notation rather than dot: \System\

The subroutine returns true (1) if the write was successful and invalid otherwise. If the Settings file or the section does not exist, they will be created. If the VarList parameter is invalid, a blank section will be created. This is a destructive write. That is to say, the entire section of the file is overwritten by the new section, regardless of the contents of either.
Searches performed by this function are case insensitive. Alignment of equal signs in the file is preserved.

Example:

If 1 Main;
[
  Vals[0][0] = "OrderlyShutdown"; 
  Vals[1][0] = 1; 
  Vals[0][1] = "ShdownOnLowBattery"; 
  Vals[1][1] = 1; 
  System.WriteSectINI("C:\VTScada\Setup.INI" { Name of file }, 
    "System" { Name of section }, 
  Vals { Arrays of data }, 
  0 { Write file format }); 
]

This causes the variables OrderlyShutdown and ShutdownOnLowBattery in the System section of the Setup.INI file to have their values set to 1 and 1.