Dim Ret As Long
Dim Start As Long
Public FileName As String
Const BufSize = 10240
Dim buf As String * BufSize
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 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
Private 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
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, 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
Public Sub SetValue(ByVal clsName As String, ByVal key As String, ByVal V As String)
Ret = WritePrivateProfileString(clsName, key, V, FileName)
End Sub
Public Function GetValue(ByVal clsName As String, ByVal key As String) As String
Ret = GetPrivateProfileString(clsName, key, "", buf, BufSize, FileName)
Start = 1
GetValue = RetStr()
End Function
Private Function RetStr() As String
Dim i As Long
i = InStr(Start, buf, Chr(0))
If i > Start Then
RetStr = Mid(buf, Start, i - Start)
End If
Start = i + 1
End Function
至此已经完成了对一个完整的独立模块的封装,接下来就来看看怎么引用(其实看完上面程序就明了了)
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/