Back

Topic

[KB591]How to read/write an INI file using SCADA BASIC

Tags: Scada Basic, Scripting

12 years ago
By RM
Options
Print
Applies to:

PcVue all versions


Summary:

Two functions to read/write an INI file using SCADA BASIC


Details:

Two functions to read an INI style configuration file from PcVue.

Supports any file (doesn’t have to be a .INI) that folllows the format of sections (between square brackets) and keys with values.
For example (from HDS.DAT):

[General]
DefaultDataConnectionType=2
DefaultConnectionString=
DefaultSecureConnectionString=
AutomaticStart=1
UseDefaultLocalDatabasesDir=1
LocalDatabasesDir=
HistoricalLanguage=9

The two functions are:

ReadIniFile(FileName, SectionName, KeyName, DefaultValue)
           FileName => the name of the file
           SectionName => the name of the section (between square brackets)
           KeyName => the key to read in the section
           DefaultValue => value that will be returned if key is not found in the file (must be a string)
The return is a string value

WriteIniFile(FileName, SectionName, KeyName, NewValue)
          FileName => the name of the file
          SectionName => the name of the section (between square brackets)
          KeyName => the key to read in the section
          NewValue => the new value to write (must be a string)
No return value. The file must exist. If the key doesn’t exist it is automatically added.

Note that the strings passed to the functions as parameters are cAsE sEnSiTiVe.

Download attachments: INI_FILE.svb.txt


Created on: 29 Aug 2012 Last update: 13 May 2024