Results 1 to 3 of 3

Thread: Problems with GetPrivateProfileString

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Posts
    161

    Question

    I have found here tons of examples to use this API function. However, I am still having trouble using it.

    It works fine when placing the returned data in a TextBox but I need to place it in a String variable and I get funky characters after the useful data I am looking for...

    Here is my code:

    Code:
    Public Function GetBarcode() As String
    Dim lRetVal As Long
    Dim sTemp As String * 50
    
    m_strFullName = "c:\temp\MyFile.ini"
    lRetVal = GetPrivateProfileString("Fiber Data", "ID", "", sTemp, Len(sTemp), m_strFullName)
    
    If lRetVal = 0 Then
        GetBarcode = ""
    Else
        GetBarcode = UCase(Trim(sTemp))
    End If
    
    End Function
    Any ideas ? I'm lost...

    Thanks !

  2. #2
    Guest
    Try this:

    Code:
    Public 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
    
    Public Function readini(strsection As String, strkey As String, strfullpath As String) As String
       Dim strbuffer As String
       Let strbuffer$ = String$(750, Chr$(0&))
       Let readini$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
    End Function
    
    Public Function GetBarcode() As String
    Dim lRetVal As Long
    Dim sTemp As String * 50
    
    m_strFullName = "c:\temp\MyFile.ini"
    lRetVal = Readini("Fiber Data", "ID", m_strFullName)
    
    If lRetVal = 0 Then
        GetBarcode = ""
    Else
        GetBarcode = UCase(Trim(sTemp))
    End If
    
    End Function
    Not sure what your exactly doing, but I hope you understand what I'm trying to show you.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Posts
    161
    Thanks a lot !

    Really, the solution to my problem was much simpler, but you pointed me to it...

    What I was missing is that the returned value from this API is the length of the string returned. I just need to use that in a 'Left' function, and it works...

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