October 23, 2018
Hot Topics:

VB TIP: Using INI Files

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

You may still need to use INI files in your applications - this tip shows you how.

Option Explicit
Global inifile$

Function MakePath$(ByVal drv$, ByVal subdir$)

Do While Right$(drv$, 1) = "\"
drv$ = Left$(drv$, Len(drv$) - 1)

Do While Left$(subdir$, 1) = "\"
subdir$ = Mid$(subdir, 2)

MakePath$ = drv$ + "\" + subdir$

End Function

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

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 cmdWrite_Click()
rslt = WritePrivateProfileString("Main", _
                       "Hello", _
                       Format$(Check1.Value), _
End Sub

Private Sub Form_Load()
inifile$ = MakePath$(App.Path, App.EXEName + ".INI")
End Sub

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date