I have been using this class ini file for sometime and the saving defaults has never worked. I now need it to work. It just not save a default value, What is causing this ?
Private m_sPath As String
Private m_sKey As String
Private m_sSection As String
Private m_sDefault As String
Private m_lLastReturnCode As Long
' Profile String functions:
Private Declare Function WritePrivateProfileString _
Lib "kernel32" _
Alias "WritePrivateProfileString
A" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString _
Lib "kernel32" _
Alias "GetPrivateProfileStringA"
(ByVal lpApplicationName As Any, _
ByVal lpKeyName As Any, _
ByVal lpDefault As Any, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Property Get LastReturnCode() As Long
LastReturnCode = m_lLastReturnCode
End Property
Property Get success() As Boolean
success = (m_lLastReturnCode <> 0)
End Property
Property Let Default(sDefault As String)
m_sDefault = sDefault
End Property
Property Get Default() As String
Default = m_sDefault
End Property
Property Let Path(sPath As String)
m_sPath = sPath
End Property
Property Get Path() As String
Path = m_sPath
End Property
Property Let Key(sKey As String)
m_sKey = sKey
End Property
Property Get Key() As String
Key = m_sKey
End Property
Property Let Section(sSection As String)
m_sSection = sSection
End Property
Property Get Section() As String
Section = m_sSection
End Property
Property Get Value() As String
Dim sBuf As String
Dim iSize As String
Dim iRetCode As Integer
sBuf = space$(255)
iSize = Len(sBuf)
iRetCode = GetPrivateProfileString(m_
sSection, m_sKey, m_sDefault, sBuf, iSize, m_sPath)
If (iSize > 0) Then
Value = Left$(sBuf, iRetCode)
Else
Value = ""
End If
End Property
Property Let Value(sValue As String)
Dim iPos As Integer
' Strip chr$(0):
iPos = InStr(sValue, Chr$(0))
Do While iPos <> 0
sValue = Left$(sValue, (iPos - 1)) & Mid$(sValue, (iPos + 1))
iPos = InStr(sValue, Chr$(0))
Loop
'MsgBox m_sPath
m_lLastReturnCode = WritePrivateProfileString(
m_sSection
, m_sKey, sValue, m_sPath)
End Property
Public Sub DeleteKey()
m_lLastReturnCode = WritePrivateProfileString(
m_sSection
, m_sKey, 0&, m_sPath)
End Sub
Public Sub DeleteSection()
m_lLastReturnCode = WritePrivateProfileString(
m_sSection
, 0&, 0&, m_sPath)
End Sub
Property Get IniSection() As String
Dim sBuf As String
Dim iSize As String
Dim iRetCode As Integer
sBuf = space$(8192)
iSize = Len(sBuf)
iRetCode = GetPrivateProfileString(m_
sSection, 0&, m_sDefault, sBuf, iSize, m_sPath)
If (iSize > 0) Then
IniSection = Left$(sBuf, iRetCode)
Else
IniSection = ""
End If
End Property
Property Let IniSection(sSection As String)
m_lLastReturnCode = WritePrivateProfileString(
m_sSection
, 0&, sSection, m_sPath)
End Property
Property Get Sections() As String
Dim sBuf As String
Dim iSize As String
Dim iRetCode As Integer
sBuf = space$(8192)
iSize = Len(sBuf)
iRetCode = GetPrivateProfileString(0&
, 0&, m_sDefault, sBuf, iSize, m_sPath)
If (iSize > 0) Then
Sections = Left$(sBuf, iRetCode)
Else
Sections = ""
End If
End Property
Start Free Trial