Question about INI files

Tuskony
04-04-2003, 12:40 AM
Is there anyway you can delete values out of an INI file?

I have a program that allows the user to define a list of strings. Then that list gets saved to an ini file. The problem is that if the person shortens the string list to something that is short then what is saved in the ini file, the old values in the ini file don't get deleted. (Sorry if this sounds confusing).

Robse
04-04-2003, 01:02 AM
I believe not, but if you've got an updated list, you can always
overwrite it...

darkolaus
04-04-2003, 01:07 AM
Guess this Program uses the GetPrivateProfileString and WritePrivateProfileString API's (atleast i would do this). If you write an entry, the value will be replaced or created, no values will be deleted.

Just ignore those values :>.

darkolaus
04-04-2003, 01:08 AM
Well if this ini file is written as Textfile, overwriting would do it, as Robse said.

NeonBurner
04-04-2003, 01:10 AM
i suppose u could save in registry the last entry and compare before updating ini , then update registry after ini updated but really save urself some trouble and just

Open App.Path & "\" & strName & ".ini" For Output As #1
print #1 strBlah
Close #1

and rewrite it everytime

P.S. no anything bout scheduled task coding? =)

Tuskony
04-04-2003, 01:14 AM
Yeah, the proggie uses the Get/Write APIs.

The program does overwrite the old values. But if the current list is shorter then the last list that is saved, the remainer of the Old LIst - The Current List sizes remains in the ini file. The program DOES ignore these values, but it looks messy :D

Robse
04-04-2003, 01:23 AM
Well I meant something like this:

1. Read in the ini (e.g. into an array, a control, an object...)
2. Let the user modify the list
3. When the user chooses to save the list:
a) Kill the old ini
b) Write ini

That way you effectively have deleted the items from the old ini.

darkolaus
04-04-2003, 01:24 AM
:D

Maybe someone knows how to delete specific lines out of a file, i don't....

Robse
04-04-2003, 01:26 AM
:D

Maybe someone knows how to delete specific lines out of a file, i don't....

You could also do a comparison of the ini file and the list you've
got in memory, and then read in the ini file with Line Input,
and then search for entries to be deleted...In this case I think
it would be easier to just erase the old file.

darkolaus
04-04-2003, 01:29 AM
Might be the only option, too. Have never read sth about deleting Lines from a file.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum