Try this example
VB Code:
  1. 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
  2. Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
  3. Private Sub Form_Load()
  4.     Dim Ret As String, NC As Long
  5.     'Write the setting to the file (c:\test.ini) under
  6.     '   Project1 -> Keyname
  7.     WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
  8.     'Create a buffer
  9.     Ret = String(255, 0)
  10.     'Retrieve the string
  11.     NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
  12.     'NC is the number of characters copied to the buffer
  13.     If NC <> 0 Then Ret = Left$(Ret, NC)
  14.     'Show our string
  15.     MsgBox Ret
  16.     'Delete the file
  17.    ' Kill "c:\test.ini"
  18. End Sub