L
lgewirtz5
I'm using the below code to write to and read from 2 ini files. My
problem is that the function, GetPrivateProfileString32, strips out all
code it thinks is extraneous from the end of the string I'm reading
from the ini file. However, when i save a string with a space at the
end, I need to read the string back including the end space. Does
anyone know a succint and reliable way to keep this space?
Thanks,
Liz
Private Declare Function GetPrivateProfileStringA Lib _
"Kernel32" (ByVal strSection As String, _
ByVal strKey As String, ByVal strDefault As String, _
ByVal strReturnedString As String, _
ByVal lngSize As Long, ByVal strFileNameName As String) As Long
Private Declare Function WritePrivateProfileStringA Lib _
"Kernel32" (ByVal strSection As String, _
ByVal strKey As String, ByVal strString As String, _
ByVal strFileNameName As String) As Long
Public Function GetPrivateProfileString32(ByVal strFileName As String,
_
ByVal strSection As String, ByVal strKey As String, _
Optional strDefault) As String
Dim strReturnString As String, lngSize As Long, lngValid As Long
On Error Resume Next
If IsMissing(strDefault) Then strDefault = ""
strReturnString = Space(1024)
lngSize = Len(strReturnString)
lngValid = GetPrivateProfileStringA(strSection, strKey, _
strDefault, strReturnString, lngSize, strFileName)
If lngValid = 0 Then
LoopCounter = 0
End If
GetPrivateProfileString32 = Left(strReturnString, lngValid)
On Error GoTo 0
End Function
Public Function WritePrivateProfileString32(ByVal strFileName As
String, _
ByVal strSection As String, ByVal strKey As String, _
ByVal strValue As String) As Boolean
Dim lngValid As Long
On Error Resume Next
lngValid = WritePrivateProfileStringA(strSection, strKey, _
strValue, strFileName)
If lngValid > 0 Then WritePrivateProfileString32 = True
On Error GoTo 0
End Function
problem is that the function, GetPrivateProfileString32, strips out all
code it thinks is extraneous from the end of the string I'm reading
from the ini file. However, when i save a string with a space at the
end, I need to read the string back including the end space. Does
anyone know a succint and reliable way to keep this space?
Thanks,
Liz
Private Declare Function GetPrivateProfileStringA Lib _
"Kernel32" (ByVal strSection As String, _
ByVal strKey As String, ByVal strDefault As String, _
ByVal strReturnedString As String, _
ByVal lngSize As Long, ByVal strFileNameName As String) As Long
Private Declare Function WritePrivateProfileStringA Lib _
"Kernel32" (ByVal strSection As String, _
ByVal strKey As String, ByVal strString As String, _
ByVal strFileNameName As String) As Long
Public Function GetPrivateProfileString32(ByVal strFileName As String,
_
ByVal strSection As String, ByVal strKey As String, _
Optional strDefault) As String
Dim strReturnString As String, lngSize As Long, lngValid As Long
On Error Resume Next
If IsMissing(strDefault) Then strDefault = ""
strReturnString = Space(1024)
lngSize = Len(strReturnString)
lngValid = GetPrivateProfileStringA(strSection, strKey, _
strDefault, strReturnString, lngSize, strFileName)
If lngValid = 0 Then
LoopCounter = 0
End If
GetPrivateProfileString32 = Left(strReturnString, lngValid)
On Error GoTo 0
End Function
Public Function WritePrivateProfileString32(ByVal strFileName As
String, _
ByVal strSection As String, ByVal strKey As String, _
ByVal strValue As String) As Boolean
Dim lngValid As Long
On Error Resume Next
lngValid = WritePrivateProfileStringA(strSection, strKey, _
strValue, strFileName)
If lngValid > 0 Then WritePrivateProfileString32 = True
On Error GoTo 0
End Function