درود به شما دوست عزیز با کدهای زیر میتونید تغییرات optionها رو درون یک فایل.ini ذخیره و باز یابی کنی.
این کدو داخل ماژول بنویس:
Option Explicit
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
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 GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Function GetProfile(lpAppName$, lpKeyName$, lpDefault, lpFileName$)
Dim lpReturnString$, nSize%, Valid%
lpReturnString$ = Space$(128)
nSize% = Len(lpReturnString$)
Valid% = GetPrivateProfileString(ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault, ByVal lpReturnString$, ByVal nSize%, ByVal lpFileName$)
GetProfile = Left$(lpReturnString$, Valid%)
End Function
Sub WriteProfile(lpAppName$, lpKeyName$, lpString$, lpFileName$)
Dim Valid%
Valid% = WritePrivateProfileString(lpAppName$, lpKeyName$, lpString$, lpFileName$)
End Sub
این هم مثال برای استفاده:
Dim INIFile As String ' Variable for IN-file
Dim bol_a As Boolean
Private Sub Form_Load()
INIFile = App.Path & "\Settings.ini"
If GetProfile("Settings", "bol_a", "", INIFile) <> "" Then
Check1.Value = GetProfile("Settings", "bol_a", "", INIFile)
End If
If GetProfile("Settings", "with", "", INIFile) <> "" Then
Me.Width = GetProfile("Settings", "with", "", INIFile)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
WriteProfile "Settings", "with", Me.Width, INIFile
WriteProfile "Settings", "bol_a", Check1.Value, INIFile
End Sub
در اخر اینکه باید بصورت دستی فایلSettings.ini را درکنار برنامه بسازی.(برای این مثال)