LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

change the value of an item in .ini file

Solved!
Go to solution

Hello, 

I have a question regarding .ini files.

I have a .ini file with multiple sections each one contains different items like this :

 

[PORTCOM]
portNumber=38
baudRate=9600
parity=0

[DOUCHETTE]

LecteurCodeBarre_PortCom= 7
NbrTestRefDummy = 100

 

I can perfectly read every item's values. 

I want to change the "NbrTestRefDummy" value and write instead a new value. So I made a Numeric to write the value I want and a command Button to change the initial value in the .ini file with the new value taped in the Numeric.

 

My code is like this :

 

int CVICALLBACK CMD_POSTE_INI_2 (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
static IniText handleFichierIni = 0;
static char g_fileName[MAX_PATHNAME_LEN];
switch (event)
{
case EVENT_COMMIT:

GetCtrlVal(panel,PANEL_SAIS_NV_NBR,&NV_Valeur);
GetDir ( RepertoireTravail);
sprintf(g_fileName,"%s\\Config.ini",RepertoireTravail);

handleFichierIni = Ini_New (1);
Ini_PutInt (handleFichierIni, "DOUCHETTE", "NbrTestRefDummy", NV_Valeur);
Ini_WriteToFile (handleFichierIni, g_fileName);
Ini_Dispose (handleFichierIni);

break;
}
return 0;
}

 

My problem is when the button is clicked, I have all the .ini file sections and items deleted and I only find the item that I changed its value with the new value ( here "NbrTestRefDummy"). 

 

my .ini file is like this :

 

[DOUCHETTE]

NbrTestRefDummy = 200

 

Could you please help me with this? I don't need to delete all the sections and items in the file. I need just to change the value of one item only.

 

0 Kudos
Message 1 of 3
(1,673 Views)
Solution
Accepted by topic author ch1994

This is obvious if you think to it: the instrument writes to disk what you have prepared in the IniFileobject, that is just the single field you have handled.

Simply read the file with Ini_ReadFromFile immediately after creating the IniFile object, next update the value you want and finally write the object to disk.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(1,658 Views)
Solution
Accepted by topic author ch1994

Exactly this is what I've done and it works.

Thank you Roberto.

0 Kudos
Message 3 of 3
(1,627 Views)