LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to add comment string and line feed while writing configuration file?

Hello,

I had trouble modifying the configuration file. My program can read and write configuration file. But the configuration file is not what I want.
Instead It shows clump of strings with no clear of grouping by statements.  I wanted to add newline under each [statement] and  comment to top of the string, I had a hard time modifying the file using string and file I/O functions. Sometimes the string output and file outout look different.

Written file:

[statement1]
blah
blah
blah
[statement2]
blah
blah
blah
[statement3]
blah
blah
blah

Modified File:

Comment blah blah blah...

[statement1]
blah
blah
blah
[statement2]
blah
blah
blah
[statement3]
blah
blah
blah

Any solutions?
Clement
0 Kudos
Message 1 of 6
(8,256 Views)
Hi astroboy,

some questions:
Which LV version do you use?
Which file functions do you use?
Do you use the config file functions (aka ini-files)?
Can you attach your vi here in the forum?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(8,252 Views)
Hi GerdW.
Thanks.
I managed to figure out. String and file IO functions are really knottly.
If u wish, u may have my codes  and give your comments.

Here's attached. These files are in version 7.1
rewrite_config.vi is sub-vi for write_config.vi.
so run write_config.vi.

Thanks Pal.
Clement
Download All
0 Kudos
Message 3 of 6
(8,248 Views)
Hi astroboy,

your vis look quite ok Smiley Happy
I just made comments on what I would prefer...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 6
(8,243 Views)
Clement,

One approach I have taken to put comments into a config file is to create a Section called [Notes] (or some other term if "Notes" happens to be a valid section of keyname). I restrict each note to be a single line (no end of line characters permitted) and define the keys as Note0=, Note1=,... so that the Notes can be read or written like elements of a string array.

[Notes]
Note0=Put first note here.
Note1=Second note.
[Real section]
realKey=

Lynn
0 Kudos
Message 5 of 6
(8,235 Views)

Begin and end each comment line with "\\" characters.  Extra carriage return\line feed characters are allowed (to improve readability).  I have only tried this on Windows XP so I don't know if it will work on other platforms.  Also, I am creating my configuration files by hand in a text editor (rather than generating them programmatically through LabVIEW).  However, I am reading in the contents of the configuration files programmatically through LabVIEW.

 

Here is an example configuration file:

 

 

 

[Button1]
Text=Production Testing
Privileges=Operator,Technician,Admin
VI Path=C:\\C4Test\\Strider\\software\\labview\\Production Testing.vi

 

[Button2]
Text=Advanced Testing
Privileges=Technician,Admin
VI Path=C:\\C4Test\\Strider\\software\\labview\\Advanced Testing.vi

 

[Button3]
Text=Maintenance
Privileges=Technician,Admin
VI Path=C:\\C4Test\\Strider\\software\\labview\\Maintenance.vi

 

[Button4]
Text=Updates
Privileges=Technician,Admin
VI Path=C:\\C4Test\\Strider\\software\\labview\\Updates.vi

 

[Auxiliary1]
Text=Documents
Privileges=Operator,Technician,Admin
VI Path=C:\\C4Test\\Strider\\software\\labview\\Documents.vi

 

[Auxiliary2]
Text=Home
Privileges=Operator,Technician,Admin
VI Path=C:\\C4Test\\Strider\\software\\labview\\Home.vi

 


\\In this configuration file, square brackets enclose each section name. Every section name must be unique.\\
\\Sections contain key/value pairs separated by an equal sign. Within each section, every key name must be unique.\\
\\The key name represents a configuration preference and the value name represents the setting for that preference.\\

0 Kudos
Message 6 of 6
(7,887 Views)