INI讀寫,很常用到的功能
放兩個textbox,兩個Command button,以下為code
Option Explicit
'寫入資料至.ini檔中的某KEY
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
'讀取ini檔中某KEY中的整數
Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias _
"GetPrivateProfileIntA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal nDefault As Long, _
ByVal lpFileName As String) As Long
Private Sub Command1_Click() '寫入
WritePrivateProfileString "Login", "Depart", CStr(Text1.Text), App.Path & "\config.ini" 'text1
WritePrivateProfileString "Login", "part", CStr(Text2.Text), App.Path & "\config.ini" 'text2
End Sub
Private Sub Command2_Click() '讀取
Text1.Text = GetPrivateProfileInt("Login", "Depart", 0, App.Path & "\config.ini ")
Text2.Text = GetPrivateProfileInt("Login", "part", 0, App.Path & "\config.ini ")
End Sub