
Attribute VB_Name = "INIReadWrite"
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
''lpApplicationName 要在其中写入新字串的小节名称。这个字串不区分大小写
''lpszSection String 指定要在其中写入新串的小节。如尚不存在,会创建这个小节。这个字串不区分大小写。
''lpszKeyName String 要设置的项名或条目名。这个字串不区分大小写。用vbNullString可删除这个小节的所有设置项。
''lpszString String 指定为这个项写入的字串值。用vbNullString表示删除这个项现有的字串。
''lpFileName 读取文件名
Dim INIFilePath As String
Sub SetINI(ByVal INIPath As String)
INIFilePath = INIPath
End Sub
Sub WriteKey(ByVal Section As String, ByVal Key As String, Optional ByVal KeyValue As String = "")
WritePrivateProfileString Section, Key, KeyValue, INIFilePath
End Sub
Function ReadKey(ByVal Section As String, ByVal Key As String, Optional ByVal Size As Long = 256) As String
Dim Str As String
Str = Space(Size)
If GetPrivateProfileString(Section, Key, 0, Str, Size, INIFilePath) <>0 Then ReadKey = Str
End Function
窗体的话你可以自己设计下,因为不知道你想要什么效果,或者你可以就上面的代码用MsgBox输出Key值来看看效果..
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)