-
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 !
-
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.
-
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...