Click here to Skip to main content
16,015,756 members

Comments by Bruce Munck (Top 4 by date)

Bruce Munck 31-Dec-17 10:31am View    
Well, here goes. The leading quotes are supposed to contain the name of the section enclosed in "[]". For some reason that is being deleted. If this doesn't work I guess I'll give up.
Bruce Munck 31-Dec-17 10:27am View    
Ok, I guess my entries are being changed. Let's try this: n = WritePrivateProfileString(, <key>, <value>, <inipath>). should appear in all the calls.
Bruce Munck 31-Dec-17 10:22am View    
In my comment and solution I left closed quotes where there should have been the following: "". Sorry.
Bruce Munck 31-Dec-17 10:16am View    
If you are looking for the easiest way to delete items fron an INI file, try using the API like this: n = WritePrivateProfileString("", "<key>", 0&, "<inipath>"). This will delete a single key and its value.

To delete an entire section, use this: n = WritePrivateProfileString("", 0&, "<value>", "<inipath>"). The following will do the same thing n = WritePrivateProfileString("", 0&, 0&, "<inipath>"). Use of either construct is correct, so choose the one you like best.

To add to an INI file: n = WritePrivateProfileString("", "<key>", "<value>", "<inipath>").

As for the WriteIni function in this article, I am not the author. I also ran into it while searching for ini file solutions several years ago and have been using it as written without any problems since around 2008. The only thing this code does that using the API "WritePrivateProfileString" does not do is to put a blank line between sections. So, on the one hand, if you don't need or care about blank lines making the file more readable, you really don't need to use this code since the API will do all the other formatting for you with a one-line call. On the other hand, if you like the idea of blank lines between sections, then this piece of code is an easy way of having them inserted properly. I have no idea why the author chose to make it a function, but it isn't a big chore to change it to a SUB. As for the GOTO's, I recently re-wrote this routine as a SUB and wrote all of the GOTO targets as separate SUB's and changed the GOTO's to standard calls. I think the original, with the GOTO's, looks neater than the re-written code. I am also of the opinion that the GOTO's were done properly and don't hurt anything. Having said that, I now use, and will continue to use, my re-written version of the above code, sans GOTO's, as it is more acceptable.