rickyah / ini-parser

Read/Write an INI file the easy way!
MIT License
971 stars 241 forks source link

write values into file INI #191

Closed alip1949 closed 5 years ago

alip1949 commented 5 years ago

I have an ini file with the section: [QB] Key = PO0119

To update the value of key using the following code snippet: { ParserData = new IniData (); FileIniData = new FileIniDataParser (); ParserData (stAppName) (stKey) = stVal; FileIniData. WriteFile (stFileIni, ParserData); } where: stAppName = " [QB] " stKey = " Key " stVal = " PO0120 After the command ... WriteFile. in the ini file I find 2 sections: [QB] Key = PO0119 [QB] Key = PO0120 so when I go to reread the ini file gives me error for duplicate section. How come? Where's that? Thank you

rickyah commented 5 years ago

I think the error is you have a duplicate section when what you wanted to to is to change the value of key from PO0119 to PO0120, right? However, the code snippet seems wrong; this line: ParserData (stAppName) (stKey) = stVal; shouldn't compile Did you mean? ParserData[stAppName][stKey] = stVal;

If the line abobe is your real code, everything should work, so probably FileIniData is appending to the file instead of overwritting

alip1949 commented 5 years ago

Tanks i'm sorry, The Code: ParserData. Sections (" QB "). Item (" KEY ") = stVal FileIniData. WriteFile (stFileIni, ParserData) It's the same as writing: ParserData [" QB "] [" KEY "] = stVal In reading, the statement: ParserData (stAppName) (stKey) is correct or also all written so?: ParserData [stAppName] [stKey] Thank you.

alip1949 commented 5 years ago

The Code: ParserData[stAppName][stKey] = stVal;
not compile I have the error: Error 2 Method arguments must be enclosed in parentheses. Why?? Thanks for all

alip1949 commented 5 years ago

After several tests I was able to verify that the code works and replace the value is: ParserData. Sections ("QB"). Item (" KEY") = stVal In reading, the statement: ParserData (stAppName) (stKey) Tanks for all