当前位置: 网学 > 编程文档 > VB > 正文

一个绝对经典的在VB中操作.ini文件的通用类源代码

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式

classIniFile.cls的内容:

Option Explicit

''--------classIniFile.cls  代码----------------
''这里定义了一个classIniFile类
''一个绝对经典的在VB中操作.ini文件的通用类源代码
''程序编写:中国青岛·许家国
''    2002.6.16
''E-Mail: goj2000@163.com
''HomePage: http://www.gojclub.com
''

''Private  member  that  holds  a  reference  to
''the  path  of  our  ini  file

Private strINI As String

''Windows  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

Private Sub CreateIni(strDrv As String, strDir As String)
    ''  Make  a  new  ini  file
    strINI = MakePath(strDrv, strDir)
End Sub

Public Sub WriteIniKey(strSection As String, strKey As String, strValue As String)
    ''  Write  to  strINI
    WritePrivateProfileString strSection, strKey, strValue, strINI
End Sub

Public Function GetIniKey(strSection As String, strKey As String) As String
    Dim strTmp As String
    Dim lngRet As String
    Dim I As Integer
    Dim strTmp2 As String
    
    strTmp = String$(1024, Ch

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号