您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> VB >> 辅导 >> 正文    
  VB源码推荐:一个操作Ini文件的类 【注册男护士专用博客】          

VB源码推荐:一个操作Ini文件的类

www.nanhushi.com     佚名   不详 

【VB源码推荐:一个操作Ini文件的类】

´--------cIniFile.cls 代码----------------
´这里定义了一个cIniFile类
Option Explicit

´// Private member that holds a reference to
´// the path of our ini file
Private strInI As String

´// Win API Declares
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

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 Function MakePath(ByVal strDrv As String, _
  ByVal strDir As String) As String

´// Makes an INI file: Guarantees a sub dir
Do While Right$(strDrv, 1) = "\"
   strDrv = Left$(strDrv, Len(strDrv) - 1)
Loop

Do While Left$(strDir, 1) = "\"
   strDir = Mid$(strDir, 2)
Loop

´// Return the path
MakePath = strDrv & "\" & strDir
End Function

Public Sub CreateIni(strDrv As String, strDir As String)


´// Make a new ini file
strInI = MakePath(strDrv, strDir)
End Sub

Public Sub WriteFile(strSection As String, _
strKey As String, _
strValue As String)



´// Write to strINI
WritePrivateProfileString strSection, _
   strKey, strValue, strInI
End Sub

Public Function GetFile(strSection As String, _
  strKey As String) As String

  Dim strTmp As String
  Dim lngRet As String

  strTmp = String$(100, Chr(32))
  lngRet = GetPrivateProfileString(strSection, _
    strKey, "", strTmp, _
    Len(strTmp), strInI)
    
  GetFile = strTmp

End Function

Public Property Let INIFile(ByVal New_IniPath As String)

´// Sets the new ini path
strInI = New_IniPath

End Property

Public Property Get INIFile() As String

´// Returns the current ini path
INIFile = strInI

End Property

´--------cIniFile.cls 使用举例----------------

    Dim myIniFile As New cIniFile
    
    ´---指定访问的ini文件
    If Len(App.Path) > 3 Then
        ´under disk root dir , eg: "C:\"
        myIniFile.INIFile = App.Path & "\setting.ini"
    Else
        myIniFile.INIFile = App.Path & "setting.ini"
    End If
    
    ´---写入ini文件
    myIniFile.WriteFile "setting", "username", strUser
   
    ´---读出ini文件的数据
    ´    注意,如果是字符串,则去掉末尾一个字符
    ´                              ----flybird@chinaasp.com
    strUser = Trim(myIniFile.GetFile("setting", "username"))
    strUser = Left(strUser, Len(strUser) - 1)

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目

      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)                            【进男护士社区逛逛】
    姓 名:
    * 游客填写  ·注册用户 ·忘记密码
    主 页:

    评 分:
    1分 2分 3分 4分 5分
    评论内容:
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。