10-22-2020 02:39 AM
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.
Solved! Go to Solution.
10-22-2020 03:20 AM - edited 10-22-2020 03:37 AM
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.
10-22-2020 05:30 AM
Exactly this is what I've done and it works.
Thank you Roberto.