PDA

Click to See Complete Forum and Search --> : Ini deleting


PITBULLCJR
Jan 2nd, 2000, 07:52 AM
Is there anyway to delete information in an ini file through code for instince
ini file looks like:
[Messages]
happy=how are you,i am fine

now is there away to delete the
happy=how are you,i am fine

using code? I want to be able to keep the
[Messages]

thanks so much!!

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

PITBULLCJR
Jan 2nd, 2000, 08:25 AM
Someone please help as soon as possible!!! thanks

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

MartinLiss
Jan 2nd, 2000, 08:50 AM
The only way I can think of to do it would be to treat the ini file like a "normal" file. That is, use normal reads and writes and when you get to the line you want to delete, just don't write it.

------------------
Marty

RogerH
Jan 2nd, 2000, 07:23 PM
Hi Chris,

still working hard on INI-files?

It's true, you can't delete a section (the one in []) or a key (the on before the =) by standard API-calls. The only thing you can do is to write an empty value 4 the key.

Roger

Frankiz
Jan 2nd, 2000, 07:45 PM
Hi guys,

I think this is a pretty good solution. Use this API call to have access to INI-Files.



Declare Function WritePrivateProfileString& lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Section$, ByVal KeyName$, ByVal KeyValue$, ByVal FileName$)

Sub AddToINI()
Dim rc As Long
rc = WritePrivateProfileString("Messages", _
"happy", "", "ANY.INI")
MsgBox "Key 'happy' in the Section 'Messages' is now deleted."
End Sub



If the third parameter is "" then the key will be deleted.

Regards,
Frank

Frankiz
Jan 2nd, 2000, 07:46 PM
Ups!
Linebreaks would have been good...

:-)

RogerH
Jan 2nd, 2000, 09:52 PM
Hi Frank,

sorry, doesn't work. The key is not deleted!

Roger

PITBULLCJR
Jan 3rd, 2000, 02:08 AM
Man that really sucks that you can't delete key. You know that could come in handy for one of you guys out there and I hope you think back on this and remember me. Or if any of you guys make a programming language or upgrade on an old language make sure to put in the deleting of a key. Thanks!!!!

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

PITBULLCJR
Jan 3rd, 2000, 02:11 AM
Hey wait is there a way to delete the whole thing? Like if it was
[Messages]
Happy=Hi How are you or whatever

could you delete the whole thing including the [Messages]?
Cause if i could do this i could just tell it to delete the whole thing then after it to rewrite the [Messages] and it would be all cleared. Thanks! Needless to say it is another idea that popped into my head hahahaha

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

Troy Mac
Jan 3rd, 2000, 02:47 AM
There is noway of deleteing the Key only the string. You could use the registry it is faster and simple to use.

------------------
Troy MacPherson
Customer Suport Software Analyst
t_macpherson@yahoo.com

LG
Jan 3rd, 2000, 04:04 AM
Hi,Chris.
Some time ago Joacim Andersson posted this code to delete a section:

Private Declare Function WritePrivateProfileSection Lib "kernel32" _ Alias "WritePrivateProfileSectionA" (ByVal _ lpAppName As String, ByVal lpString As _ String, ByVal lpFileName As String) As Long


Call it in the following manner:

Call WritePrivateProfileSection _("section2","","MyIniFile.ini")

Hope it help you.
Larisa

Troy Mac
Jan 3rd, 2000, 04:30 AM
That last one will delete the whole section [Messages] not just the key this is the correct way. One question PITBULLCJR if you don't have a value under the Messages section why would you want to keep it? and if it is something getting updated constantly then just re-write the whole section.

------------------
Troy MacPherson
Customer Suport Software Analyst
t_macpherson@yahoo.com

PITBULLCJR
Jan 3rd, 2000, 05:13 AM
See I have it on my program that it keeps updating things everytime something happens when it updates it it adds a number in consecutive order under the messages like
[Messages]
chris1=kldjfsf
chris2=sdafjsdfkj
chris3=asd;lfjsd
see what I am saying well these start to pile up and my program reads these and adds them to a list so I want to be able to delete them so what i was thinking on doing was just deleting the key and i see that is not possible so what I will do is just delete the whole thing and when it goes to write it again it ill just add the [messages] again. Thanks I am going to try that code right now. Thanks!!!

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

PITBULLCJR
Jan 3rd, 2000, 05:20 AM
I can't get that code to work it keeps telling me that the writeprivateprofilesection is not defined and i did put the declare the function in the module so what went wrong. Does it work for you?

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

PITBULLCJR
Jan 3rd, 2000, 11:04 AM
I wish it did work but it doesn't delete the key it does however delete the statement after the =. Yes I am still working hard on ini files. If you remember my project that I had well I have it no so you can mail back and forth and I want the ini to remember what was mailed but I want to be able to delete was in in the ini also so not to much space gets taken up and also so that it is less confusing. Well Thanks Everyone.

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

PITBULLCJR
Jan 3rd, 2000, 11:09 AM
Hay maybe just maybe is there such a thing called delete privateprofilestring ? A qild guess but who knows. Thanks again

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

MartinLiss
Jan 3rd, 2000, 11:49 AM
Once again, as RogerH and I said, there is no way to do what you want to do by using API calls. Instead of trying to use an ini file, maybe you should use a database to store and delete your messages.

------------------
Marty

onerrorgoto
Jan 3rd, 2000, 02:55 PM
Hey Pitbull
Here is the url to Joacims response.
http://www.vb-world.net/ubb/Forum1/HTML/008179.html

Did you just copy and pasted the code from larissa??
Did you remove all the underscore's from teh code or made sure the linebreaks(?) are in the right place's.
Just a thought :)

I will try the code myself in a few minutes and get rigth back to let you know if it worked.

------------------
On Error Goto Bed :0)
anders@zsystemdesign.se

YES!!'
it worket like a charm
Here is the the code I used

Public Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long

'call the function like this
Call WritePrivateProfileSection("section2","","MyIniFile.ini")


First: I hade to make the function Public because I used a module.
Second: Remove all the unserscore's to make the syntax correct
third: This function removes all keys below then [Heading]-part.

I love this, It will Bring my app to new levels of greatness ;)

Thank you Larissa and Joacim :)

[This message has been edited by onerrorgoto (edited 01-04-2000).]

PITBULLCJR
Jan 4th, 2000, 01:43 AM
It works perfectly!! It does not delete the
[messages] but it does delete the
happy=how are you....
so this is exactly what i was looking for thanks everyone for all your time and trouble!!!

------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

KENNNY
Jan 4th, 2000, 02:00 AM
use the registry cos u *can* delete keys there :p


------------------
cintel rules :p
www.cintelsoftware.co.uk