PDA

Click to See Complete Forum and Search --> : GetPrivateProfileString - Removing '0' character from string


eL_NiNo
Jul 11th, 2001, 01:26 PM
I'm using the GetPrivateProfileString API and I just realised it was causing an error to mycode. I used the CIniFile class provided on vbworld.

Look carefully at the line in red, it fills the var all with 0. I need to remove them after, how do I achieve this ?




Public Function GetFile(strSection As String, _
strKey As String) As String

Dim strTmp As String
Dim lngRet As String

strTmp = String$(100, 0)
lngRet = GetPrivateProfileString(strSection, _
strKey, "", strTmp, _
Len(strTmp), strInI)

GetFile = strTmp

End Function

denniswrenn
Jul 11th, 2001, 01:57 PM
That does not fill the string with 0's, it fills the string with nothing(I think it has the same effect as adding *100 after the variable declaration). If you add MsgBox strTemp after that line, you will see strTemp isn't filled with 0's.

eL_NiNo
Jul 11th, 2001, 03:01 PM
ok sorry, my mistake then.
It seemed to cause a problem when splitting data afer using Split() and adding to collection. Anyway I solved the problem by making a list class CList.

Thanks for the reply !

Kaverin
Jul 11th, 2001, 06:38 PM
If you're using string$(#,0), it's not filling it with nothing, it's sticking in ASCII 0, the null char. That's just not something that windows displays, and in most display things it will get turned into a space, like in the debug window. If you did want to fill it with "0", you'd give it 48 or the literal "0".