·首页 ·asp ·.net ·php ·JSP ·CGI ·数据库 ·网页设计 ·网管专栏 ·XML ·工具软件 ·办公软件 ·操作系统 ·程序设计 ·LINUX 
  当前位置: 普克>>计算机教程>>.net>>VB.Net语言>>VB.NET中读取INI文件设置信息函
flash视频教学

photoshop专题

asp.net专题

office专题

VB.NET中读取INI文件设置信息函数sdGetIniInfo


VB.Net语言 发表时间:2006-4-8 字体:  返回
 

虽然VB.NET中读取XML配置信息很方便,但有时开发的过程中还是要用到INI文件,在VB.NET中读取INI却不像VB中那么方便了,刚才写了个函数,现贴出来,也许各位能用得上。


    '函数名: sdGetIniInfo
    '功能:读取INI文件设置信息
    '参数说明:iniFile-->INI文件     iniSection--INI文件中设置的部分名称
    '作者:SD
    '日期:2005-10-11
    'Email:ztqas@126.com
    '备注:转载或修改请保留此信息
    Function sdGetIniInfo(ByVal iniFile As String, ByVal iniSection As String) As String
        If Not File.Exists(iniFile) Then
            Return "文件 " & iniFile & " 未找到,请确认路径和文件名是否正确!"
            Exit Function
        End If

        Dim iniRead As New StreamReader(iniFile)
        Dim iniStr As String = iniRead.ReadToEnd

        Dim i As Integer
        Dim cLine As Integer
        Dim noSec As Boolean = False
        Dim getValue As String = ""
        Dim cLst

        cLst = iniStr.Split(Chr(13))
        cLine = UBound(cLst)

        For i = 0 To cLine
            If cLst(i).indexof("=") > 0 Then
                If cLst(i).split("=")(0).trim() = iniSection Then
                    noSec = True
                    getValue = cLst(i).split("=")(1).trim()
                    Exit For
                End If
            End If
        Next

        If noSec = True Then
            Return getValue
        Else
            Return "没有找到 " & iniSection & " 的设置信息!"
        End If
    End Function

说明:在引用的面页中要先引用 Imports System.IO

EG:

set.ini文件内容:

[Info]
name=zhuang
age=20

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim name As String
        name = sdGetIniInfo(Application.StartupPath & "\set.ini", "name")
        MsgBox(name)
    End Sub



上一篇:解决VB.net中ReadProcessMemory的问题
下一篇:VB.NET中LISTVIEW排序

普克创业投资网刊载此文不代表同意其说法或描述,仅为提供更多信息。
在百度中搜索VB.NET中读取INI文件设置信息函数sdGetIniInfo的相关内容]   [在狗狗中搜索VB.NET中读取INI文件设置信息函数sdGetIniInfo的相关内容]
Copyright @ 2006 PUPK.COM 普克创业投资网 版权所有
 建议使用1024*768以达到最好的浏览效果