打印

几个操作INI文件的函数

[复制链接]
1825|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xnwxq|  楼主 | 2009-8-25 20:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本代码和上次的有所不同,更加稳定!
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

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:我们都是风雨中的孩子,手牵着手才不会跌倒

162

主题

294

帖子

1

粉丝