- 积分
- 73549
- 明经币
- 个
- 注册时间
- 2001-6-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 作者 于 2003-11-13 19:22:34 编辑
- '获取INI文件的整个Section段的值
- 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
- '获取INI文件某个Section段的某个Key的值
- 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
- '将一个格式化的Section段写入INI文件中
- Declare Function WritePrivateProfileSection Lib "kernel32" _
- Alias "WritePrivateProfileSectionA" _
- (ByVal lpAppName As String, _
- ByVal lpString As Any, _
- ByVal lpFileName As String) As Long
- '将一个字符串写入INI文件中的Section中的Key值
- 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
- '以下是把API函数转化成易懂的函数供大家使用:
- Public Function GetSection(IniFile As String, Section As String) As Variant
- Dim sSection As String * 32767
- Dim S As String
-
- GetPrivateProfileSection Section, sSection, Len(sSection), IniFile
- S = sSection
- S = Left(S, InStr(1, S, vbNullChar & vbNullChar) - 1)
- S = Trim(S)
- GetSection = Split(S, vbNullChar)
- End Function
- Public Function GetKey(IniFile As String, Section As String, Key As String, Default As String) As String
- Dim Value As String * 32767
- Dim S As String
- GetPrivateProfileString Section, Key, Default, Value, Len(Value), IniFile
- S = Value
- S = Left(S, InStr(1, S, vbNullChar) - 1)
- S = Trim(S)
- GetKey = S
- End Function
- Public Sub SetSection(IniFile As String, Section As String, Value As Variant)
- Dim i As Integer
- Dim S As String
- For i = LBound(Value) To UBound(Value)
- If i = 0 Then
- S = Value(i)
- Else
- S = S & vbNullChar & Value(i)
- End If
- Next i
- S = S & vbNullChar & vbNullChar
- S = Value
- WritePrivateProfileSection Section, S, IniFile
- End Sub
- Public Sub SetKey(IniFile As String, Section As String, Key As String, Value As String)
- WritePrivateProfileString Section, Key, Value, IniFile
- End Sub
|
|