首页 » Visual Basic » VB操作ini文件的函数
VB操作ini文件的函数
WriteINI "e", "f", "DF", "c:\a.ini") '写入 GetINI("e", "f", , "c:\a.ini") '读取 '代码,将以下代码保存为一个模块 Public 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 Public 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 Function GetINI(ApplicationName As String, KeyName As String, Optional ByVal Default As String = "", Optional ByVal FileName As String = "config.ini") As String Dim Retval As Long Dim Value As String FileName = IIf(Mid(FileName, 2, 2) = ":\", FileName, Replace(App.Path & "\" & FileName, "\\", "\")) Value = Space(128) Retval = GetPrivateProfileString(ApplicationName, KeyName, Default, Value, Len(Value), FileName) GetINI = Left(Trim(Value), Len(Trim(Value)) - 1) End Function Public Sub WriteINI(ApplicationName As String, KeyName As String, Value As String, Optional ByVal FileName As String = "config.ini") Dim Retval As Long FileName = IIf(Mid(FileName, 2, 2) = ":\", FileName, Replace(App.Path & "\" & FileName, "\\", "\")) Retval = WritePrivateProfileString(ApplicationName, KeyName, Value, FileName) End Sub
上一篇: VB控制鼠标,设置获取鼠标位置
下一篇: vb拖盘图标完美实现例子
目前这篇文章有4条评论(Rss)