12-16-2021 12:53 AM
Hello all, I have one .ini file I wanted to open the .ini file and change only one particular key value and save the file. I have tried doing it as a text file but not able to get perfect vi for .ini file. can someone please help me. In given file I have to change CMD="8" to CMD="6"
[CMD_cmd3]
CMD = "8"
Timeout = "10"
any help will be accepted! Thanks for helping us to learn Labview
Solved! Go to Solution.
12-16-2021 01:18 AM - edited 12-16-2021 01:27 AM
LabVIEW has a set of VIs for working with ini-style files: Configuration File VIs. You find them in 'File I/O' palette.
It is as easy as open file, write key and close file.
12-16-2021 01:24 AM - edited 12-16-2021 01:26 AM
Hi Lamar,
you can directly work with .ini files in LabVIEW so [CMD_cmd3] will be your section and CMD will be your key.
In Example Finder you can look up "Configuration (INI) File.lvproj", which explains the work with ini files nicely.
If you need to write your value in parenthesis, then change the data type of CMD Value to string and pass it to the Write Key.vi (it's polymorphic).
EDIT: oh, UliB was faster than me (at least it's good to know that we're giving consistent advises 😄 )
12-16-2021 02:14 AM
@Ajskrim wrote:
Hi Lamar,
you can directly work with .ini files in LabVIEW so [CMD_cmd3] will be your section and CMD will be your key.
In Example Finder you can look up "Configuration (INI) File.lvproj", which explains the work with ini files nicely.
If you need to write your value in parenthesis, then change the data type of CMD Value to string and pass it to the Write Key.vi (it's polymorphic).
EDIT: oh, UliB was faster than me (at least it's good to know that we're giving consistent advises 😄 )
Not to bring the hammer down on you, but this could've been made a LOT neater. There is no reason to have wire bends all over the place and haphazardly placed block diagram constants. Even if you were lazy, using the BD cleanup tool would've made a decent block diagram. If you're going to post code as a solution, you should follow best LabVIEW practices.
12-16-2021 02:32 AM
Indeed, that is a very ugly piece of code 😄
Thanks for pointing this out, next time I'll try to do better job.
12-16-2021 02:35 AM
Guys.... sometimes you need to pay attention to the little things.
@lamar, when you edited your ini file with notepad you inadvertently changed the file name from
Test.ini. to
Test.ini.txt
So, test.ini never changed and the code still ran with the original settings.
12-16-2021 02:42 AM
Pardon! got it will take care of it
12-16-2021 02:43 AM
Thats Awesome! Thank you so much for this vi. Now i got it where I was wrong.
12-16-2021 02:44 AM
Yes this is definitely good to go. Thank you so much for helping noob labview developer.
12-16-2021 12:09 PM
@JÞB wrote:
Guys.... sometimes you need to pay attention to the little things.
@lamar, when you edited your ini file with notepad you inadvertently changed the file name from
Test.ini. to
Test.ini.txt
So, test.ini never changed and the code still ran with the original settings.
Oh, well. Everyone got a lesson in how to use the config VIs and some advice on LV best practices. 😄