|
-
January 13th, 2000, 03:09 PM
#1
Question with GetPrivateProfileString
I use it to retrieve value from .ini file but when on Form_load it reads the value, then it delete it so basically all the data from .ini file will be lost if I'll open then close my program and a second later open it again.. I read from INI when form loads and write to it when for unloads, but how can I prevent data (that was read from ini) from being deleted, I just want to read from INI and leave INI alone, but on form unload it will just overwrite existed value, without losing any data from INI
Thank You
-
January 13th, 2000, 03:14 PM
#2
Re: Question with GetPrivateProfileString
GetPrivateProfileString doesn't delete value that it reads, you must be resetting/passing blank values to the WritePrivateProfileString API, check the Values you are passing to this API in your Forms Unload Event.
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
January 13th, 2000, 04:17 PM
#3
Re: Question with GetPrivateProfileString
But how can I fix the code so data inside .ini will remain after GetPrivateProfileString was used
-
January 14th, 2000, 04:00 AM
#4
Re: Question with GetPrivateProfileString
Like Aaron said, the GetPrivateProfileString doesn't remove items from your ini file - Are you sure that something else isn't removing them (Notepad etc ?)
Try it with this simple form :
option Explicit
'
private Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" (byval lpApplicationName as string, _
byval lpKeyName as Any, byval lpDefault as string, _
byval lpReturnedString as string, byval nSize as Long, _
byval lpFileName as string) as Long
'
private Sub Form_Load()
Dim sBuffer as string
Dim lRet as Long
Dim lSize as Long
'
lSize = 255
sBuffer = string$(lSize, vbNullChar)
lRet = GetPrivateProfileString("me", "TEST", "empty !", sBuffer, _
lSize, "c:\test.ini")
If lRet > 0 then MsgBox Left$(sBuffer, lRet)
'
End Sub
And this ini file in c:\test.ini :
[ME]
TEST=Chris Was Here
- run the program and then close the form - you should see that the ini file hasn't been changed once the program has finished.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
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
|