VB Code:
Option Explicit
Private 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
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
Private 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
Private Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
End Sub
Private Sub cmdLoad_Click()
Dim sFileName As String
Dim c As Control
'Load data from Ini File
sFileName = App.Path & "\" & Me.Name & ".INI"
For Each c In Me
If TypeOf c Is TextBox Then c.Text = ReadINI("DATA_TextBox", c.Name, sFileName)
If TypeOf c Is CheckBox Then c.Value = Val(ReadINI("DATA_CheckBox", c.Name, sFileName))
Next c
End Sub
Private Sub cmdSave_Click()
Dim sFileName As String
Dim c As Control
'Save data to ini file
sFileName = App.Path & "\" & Me.Name & ".INI"
For Each c In Me
If TypeOf c Is TextBox Then WriteINI "DATA_TextBox", c.Name, c.Text, sFileName
If TypeOf c Is CheckBox Then WriteINI "DATA_CheckBox", c.Name, c.Value, sFileName
Next c
End Sub