" id="b1img" alt="米课”N+1“思维建站-非官方免费技术支持,Wordpress/Zencart/Opencart建站、SEO" title="米课”N+1“思维建站-非官方免费技术支持,Wordpress/Zencart/Opencart建站、SEO">
  • " alt="米课”N+1“思维建站-非官方免费技术支持,Wordpress/Zencart/Opencart建站、SEO" title="米课”N+1“思维建站-非官方免费技术支持,Wordpress/Zencart/Opencart建站、SEO" />
  • " alt="Windows/Linux服务器运维技术支持 环境搭建、应用发布、服务器管理、虚拟化、云计算" title="Windows/Linux服务器运维技术支持 环境搭建、应用发布、服务器管理、虚拟化、云计算" />
  • " alt="高校/小型企业网络运维与建设免费技术支持,网络规划、网络优化、故障排除、网络管理" title="高校/小型企业网络运维与建设免费技术支持,网络规划、网络优化、故障排除、网络管理" />

VB – ini文件读写操作实例代码

程序设计2005-04-26 itlogger阅读(654) 评论(0)
ini文件读写操作实例代码
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 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 GetIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal FileName As String) As String
Dim GetStr As String

On Error GoTo GetIniStrErr

If VBA.Trim(In_Key) = “” Then
GoTo GetIniStrErr
End If

GetStr = VBA.String(128, 0)
GetPrivateProfileString AppName, In_Key, “”, GetStr, 256, FileName ‘App.Path & “SourceDB.ini”
GetStr = VBA.Replace(GetStr, VBA.Chr(0), “”)
If GetStr = “” Then
GoTo GetIniStrErr
Else
GetIniStr = GetStr
GetStr = “”
End If

Exit Function
GetIniStrErr:
Err.Clear
GetIniStr = “”
GetStr = “”
End Function
‘———————————————————————————————————————————————
Public Function WriteIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal In_Data As String, ByVal FileName As String) As Boolean
On Error GoTo WriteIniStrErr
WriteIniStr = True
If VBA.Trim(In_Key) = “” Or VBA.Trim(AppName) = “” Then
GoTo WriteIniStrErr
Else
WritePrivateProfileString AppName, In_Key, In_Data, FileName
End If
Exit Function
WriteIniStrErr:
Err.Clear
WriteIniStr = False
End Function
‘———————————————————————————————————————————————
应用实例
WriteIniStr “Lab”, “Uid”, Uid, 文件名(路径)
Uid = GetIniStr(“Lab”, “Uid”, 文件名(路径))

转载请注明 :IT樵客
文章地址:http://www.itlogger.com/program/54.html
标签:
相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注