本代码和上次的有所不同,更加稳定!
Function GetKeyVal(ByVal INIFileLoc As String, ByVal Section As String, ByVal Key As String)
If Dir(INIFileLoc) = "" Then MsgBox "文件没有找到: " & INIFileLoc & vbCrLf & "无法提取所需的值", vbExclamation, "INI 文件没有找到": Exit Function
Dim RetVal As String, Worked As Integer
RetVal = String$(255, 0)
Worked = GetPrivateProfileString(Section, Key, "", RetVal, Len(RetVal), INIFileLoc)
If Worked = 0 Then
GetINI = ""
Else
GetINI = Left(RetVal, InStr(RetVal, Chr(0)) - 1)
End If
End Function
Function AddToINI(ByVal INIFileLoc As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
'其实应该自动创建文件???
If Dir(INIFileLoc) = "" Then MsgBox "文件没有找到: " & INIFileLoc & vbCrLf & "无法增加所需的值", vbExclamation, "INI 文件没有找到": Exit Function
WritePrivateProfileString Section, Key, Value, INIFileLoc
End Function
Function DeleteSection(ByVal INIFileLoc As String, ByVal Section As String)
If Dir(INIFileLoc) = "" Then MsgBox "文件没有找到: " & INIFileLoc & vbCrLf & "无法删除所需的值", vbExclamation, "INI 文件没有找到": Exit Function
WritePrivateProfileString Section, vbNullString, vbNullString, INIFileLoc
End Function
Function DeleteKey(ByVal INIFileLoc As String, ByVal Section As String, ByVal Key As String)
If Dir(INIFileLoc) = "" Then MsgBox "文件没有找到: " & INIFileLoc & vbCrLf & "无法删除所需的值", vbExclamation, "INI 文件没有找到": Exit Function
WritePrivateProfileString Section, Key, vbNullString, INIFileLoc
End Function
Function DeleteKeyValue(ByVal INIFileLoc As String, ByVal Section As String, ByVal Key As String)
If Dir(INIFileLoc) = "" Then MsgBox "文件没有找到: " & INIFileLoc & vbCrLf & "Please refer To code in Function 'DeleteKeyValue'", vbExclamation, "INI 文件没有找到": Exit Function
WritePrivateProfileString Section, Key, "", INIFileLoc
End Function
'以下功能自己做喽,呵呵
Function RenameSection()
End Function
Function RenameKey()
End Function |