VB TIP: Using INI Files

Monday Nov 18th 2002 by Sam Huggill
Share:

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

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)
Loop

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

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), _
                       inifile$)
End Sub

Private Sub Form_Load()
inifile$ = MakePath$(App.Path, App.EXEName + ".INI")
End Sub
Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved