|
-
Jan 2nd, 2000, 08:52 AM
#1
Thread Starter
Hyperactive Member
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 [email protected]
-
Jan 2nd, 2000, 09:25 AM
#2
Thread Starter
Hyperactive Member
Someone please help as soon as possible!!! thanks
------------------
Sincerely,
Chris
:-) ;-)
Email [email protected]
-
Jan 2nd, 2000, 09:50 AM
#3
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
-
Jan 2nd, 2000, 08:23 PM
#4
Lively Member
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
-
Jan 2nd, 2000, 08:45 PM
#5
Junior Member
Hi guys,
I think this is a pretty good solution. Use this API call to have access to INI-Files.
Code:
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
-
Jan 2nd, 2000, 08:46 PM
#6
Junior Member
Ups!
Linebreaks would have been good...
:-)
-
Jan 2nd, 2000, 10:52 PM
#7
Lively Member
Hi Frank,
sorry, doesn't work. The key is not deleted!
Roger
-
Jan 3rd, 2000, 03:08 AM
#8
Thread Starter
Hyperactive Member
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 [email protected]
-
Jan 3rd, 2000, 03:11 AM
#9
Thread Starter
Hyperactive Member
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 [email protected]
-
Jan 3rd, 2000, 03:47 AM
#10
Hyperactive Member
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
[email protected]
-
Jan 3rd, 2000, 05:04 AM
#11
Hyperactive Member
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
-
Jan 3rd, 2000, 05:30 AM
#12
Hyperactive Member
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
[email protected]
-
Jan 3rd, 2000, 06:13 AM
#13
Thread Starter
Hyperactive Member
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 [email protected]
-
Jan 3rd, 2000, 06:20 AM
#14
Thread Starter
Hyperactive Member
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 [email protected]
-
Jan 3rd, 2000, 12:04 PM
#15
Thread Starter
Hyperactive Member
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 [email protected]
-
Jan 3rd, 2000, 12:09 PM
#16
Thread Starter
Hyperactive Member
Hay maybe just maybe is there such a thing called delete privateprofilestring ? A qild guess but who knows. Thanks again
------------------
Sincerely,
Chris
:-) ;-)
Email [email protected]
-
Jan 3rd, 2000, 12:49 PM
#17
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
-
Jan 3rd, 2000, 03:55 PM
#18
Hyperactive Member
-
Jan 4th, 2000, 02:43 AM
#19
Thread Starter
Hyperactive Member
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 [email protected]
-
Jan 4th, 2000, 03:00 AM
#20
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|