M
Mat
Hi
I have a need to write to a ini file. I have a form with
text boxes and the user will type in the data and then
click on a button to write to the ini file. However, I
cannot get it to do what I want.
I have done following:
1. In a module in the db entered :
Option Compare Database
Declare Function GetPrivateProfileString Lib "kernel32"
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName
As String, ByVal lpKeyName As String, ByVal lpDefault As
String, ByVal lpReturnedString As String, ByVal nSize As
Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32"
Alias "WritePrivateProfileStringA" (ByVal
lpApplicationName As String, ByVal lpKeyName As String,
ByVal lpString As Any, ByVal lpFileName As String) As Long
2. In the code for the form:
Option Compare Database
Function ReadINI(Section, KeyName, filename As String) As
String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section,
ByVal KeyName, "", sRet, Len(sRet), filename))
End Function
Function writeini(sSection As String, sKeyName As String,
sNewString As String, sFileName) As Integer
Dim r
r = WritePrivateProfileString(Section, KeyName,
sNewString, filename)
End Function
Private Sub Command1_Click()
Text1 = ReadINI("SMTP", "Server", "c:\program files\app"
& "\app.ini")
End Sub
Private Sub Command2_Click()
r = WritePrivateProfileString
("SMTP", "Server", "NewString", "c:\program files\app"
& "\app.ini")
End Sub
3. On the form I have 2 buttons (Command1, Command2) and
one text box (text1)
The first button reads the entry in the ini file - OK
4. The ini file has following:
[SMTP]
User Address=Bart
Server=aaaaaaaaa
I want to write/amend in the text box and then use button
2 (Command2) to write that value back to the ini file.
It will write "NewString" to the file - if it is entered
using " ", but I want it to take the value from the text1
textbox.
Can anyone help - it is driving me mad !
Thanks
Mat.
I have a need to write to a ini file. I have a form with
text boxes and the user will type in the data and then
click on a button to write to the ini file. However, I
cannot get it to do what I want.
I have done following:
1. In a module in the db entered :
Option Compare Database
Declare Function GetPrivateProfileString Lib "kernel32"
Alias "GetPrivateProfileStringA" (ByVal lpApplicationName
As String, ByVal lpKeyName As String, ByVal lpDefault As
String, ByVal lpReturnedString As String, ByVal nSize As
Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32"
Alias "WritePrivateProfileStringA" (ByVal
lpApplicationName As String, ByVal lpKeyName As String,
ByVal lpString As Any, ByVal lpFileName As String) As Long
2. In the code for the form:
Option Compare Database
Function ReadINI(Section, KeyName, filename As String) As
String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section,
ByVal KeyName, "", sRet, Len(sRet), filename))
End Function
Function writeini(sSection As String, sKeyName As String,
sNewString As String, sFileName) As Integer
Dim r
r = WritePrivateProfileString(Section, KeyName,
sNewString, filename)
End Function
Private Sub Command1_Click()
Text1 = ReadINI("SMTP", "Server", "c:\program files\app"
& "\app.ini")
End Sub
Private Sub Command2_Click()
r = WritePrivateProfileString
("SMTP", "Server", "NewString", "c:\program files\app"
& "\app.ini")
End Sub
3. On the form I have 2 buttons (Command1, Command2) and
one text box (text1)
The first button reads the entry in the ini file - OK
4. The ini file has following:
[SMTP]
User Address=Bart
Server=aaaaaaaaa
I want to write/amend in the text box and then use button
2 (Command2) to write that value back to the ini file.
It will write "NewString" to the file - if it is entered
using " ", but I want it to take the value from the text1
textbox.
Can anyone help - it is driving me mad !
Thanks
Mat.