iT邦幫忙

DAY 18
26

VB6之迴光返照系列 第 18

VB6之迴光返照- 讀寫ini檔

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


上一篇
VB6之迴光返照-labelbutton
下一篇
VB6之迴光返照- 讀取目前座標
系列文
VB6之迴光返照30

尚未有邦友留言

立即登入留言