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

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

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
r(32))
    lngRet = GetPrivateProfileString(strSection, strKey, "", strTmp, Len(strTmp), strINI)
    strTmp = Trim(strTmp)
    strTmp2 = ""
    For I = 1 To Len(strTmp)
        If Asc(Mid(strTmp, I, 1)) <> 0 Then
            strTmp2 = strTmp2 + Mid(strTmp, I, 1)
        End If
    Next I
    strTmp = strTmp2
    
    GetIniKey = strTmp
End Function

Public Property Let INIFileName(ByVal New_IniPath As String)
    ''  Sets  the  new  ini  path
    strINI = New_IniPath
End Property

Public Property Get INIFileName() As String
    ''  Returns  the  current  ini  path
    INIFileName = strINI
End Property

''***************************************清除KeyWord"键"(Sub)***********************************************
Public Function DelIniKey(ByVal SectionName As String, ByVal KeyWord As String)
    Dim RetVal As Integer
    RetVal = WritePrivateProfileString(SectionName, KeyWord, 0&, strINI)
End Function

''如果是清除section就少写一个Key多一个""。
''**************************************清除 Section"段"(Sub)***********************************************
Public Function DelIniSec(ByVal SectionName As String)      ''清除section
    Dim RetVal As Integer
    RetVal = WritePrivateProfileString(SectionName, 0&, "", strINI)
End Function



Form1中的内容:

Option Explicit

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

''定义一个.ini类型的变量
Dim DemoIni As New classIniFile

Private Sub Form_Load()
    ''对控件进行初始化
    Text1.Text = "测试一下"
    List1.Clear
    
    ''定义.ini文件名,并写入一些初始数据
    DemoIni.INIFileName = App.Path & "\demoini.ini"
    DemoIni.WriteIniKey "系统", "启动路径", App.Path
    DemoIni.WriteIniKey "系统", "可执行程序文件名", App.EXEName
    
    ''显示保存到.ini文件中的数据
    Call CmdRead_Click
End Sub

''退出程序
Private Sub CmdExit_Click()
    Unload Me
End Sub

''读取.ini文件中已经存在的数据并显示出来
Private Sub CmdRead_Click()
    Dim TestStr As String
    
&nbs

网学推荐

免费论文

原创论文

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