LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

editing single key value within ini file

Solved!
Go to solution

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

 

 

0 Kudos
Message 1 of 11
(2,907 Views)
Solution
Accepted by LamarDavisss

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.

INI-File_WriteKey.png

Message 2 of 11
(2,893 Views)
Solution
Accepted by LamarDavisss

Hi Lamar,

 

you can directly work with .ini files in LabVIEW so [CMD_cmd3] will be your section and CMD will be your key.

snp.png

 

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 😄 )

_______________________________________________________________

-Patrik
CLA || CTA
If it helps - Kudo it, if it answers - Mark As Solution
Message 3 of 11
(2,888 Views)

@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.

snp.png

 

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 11
(2,861 Views)

Indeed, that is a very ugly piece of code 😄 

Thanks for pointing this out, next time I'll try to do better job.

_______________________________________________________________

-Patrik
CLA || CTA
If it helps - Kudo it, if it answers - Mark As Solution
0 Kudos
Message 5 of 11
(2,848 Views)

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.


"Should be" isn't "Is" -Jay
Message 6 of 11
(2,846 Views)

Pardon! got it will take care of it

0 Kudos
Message 7 of 11
(2,842 Views)

Thats Awesome! Thank you so much for this vi. Now i got it where I was wrong. 

0 Kudos
Message 8 of 11
(2,841 Views)

Yes this is definitely good to go. Thank you so much for helping noob labview developer. 

0 Kudos
Message 9 of 11
(2,840 Views)

@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.  😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 11
(2,787 Views)