Results 1 to 4 of 4

Thread: GetPrivateProfileString - Removing '0' character from string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212

    GetPrivateProfileString - Removing '0' character from string

    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 ?



    Code:
    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
    Regards,

    El-Nino

  2. #2
    denniswrenn
    Guest
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    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 !
    Regards,

    El-Nino

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    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".
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width