Link to home
Start Free TrialLog in
Avatar of jpetro7
jpetro7

asked on

read ini

I'm need to read values from an ini.

What's the most basic way to use GetPrivateProfileString?

-jpetro7
Avatar of GivenRandy
GivenRandy

Something like this:

---
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Sub Form_Load()
    Dim Ret As String, NC As Long
   
    Ret = String(255, 0)
    NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
    If NC <> 0 Then Ret = Left$(Ret, NC)
    MsgBox Ret
End Sub
---
I don't think app.title is a good substitute for lpApplicationName.  This should actually be the section heading item in an ini file... the part that is inclosed in [Brackets]
ASKER CERTIFIED SOLUTION
Avatar of GivenRandy
GivenRandy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Force accepting GivenRandy's comment.

costello
Community Support Moderator @ Experts-Exchange