• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

VB读写ini文件

发布: 2007-7-14 20:28 | 作者: 佚名    | 来源: 网络转载     | 查看: 16次 | 进入软件测试论坛讨论

领测软件测试网 自从注册表诞生以来ini文件正在逐渐失去其市场占有率,然而基于ini文件的独立性,致使其还没有到达退出历史舞台的地步,很多应用程序的初始化和一些界面参数的设置仍然很愿意从ini文件中读取,为了保证操作需用参数对ini文件的读取的通明性,建议使用一个模块来完成此工作。注:所有操作调用标准的Win API函数来完成。

Dim Ret As Long

Dim Start As Long

Public FileName As String

Const BufSize = 10240

Dim buf As String * BufSize

Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long



Private 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



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 WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, 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 Sub SetValue(ByVal clsName As String, ByVal key As String, ByVal V As String)

    Ret = WritePrivateProfileString(clsName, key, V, FileName)

End Sub



Public Function GetValue(ByVal clsName As String, ByVal key As String) As String

    Ret = GetPrivateProfileString(clsName, key, "", buf, BufSize, FileName)

       Start = 1

       GetValue = RetStr()

End Function



Private Function RetStr() As String

     Dim i As Long

     i = InStr(Start, buf, Chr(0))

     If i > Start Then

       RetStr = Mid(buf, Start, i - Start)

     End If

     Start = i + 1

End Function



至此已经完成了对一个完整的独立模块的封装,接下来就来看看怎么引用(其实看完上面程序就明了了)

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网