虽然VBNET中读取XML配置信息很方便但有时开发的过程中还是要用到INI文件在VBNET中读取INI却不像VB中那么方便了刚才写了个函数现贴出来也许各位能用得上
函数名: sdGetIniInfo
功能:读取INI文件设置信息
参数说明:iniFile>INI文件 iniSectionINI文件中设置的部分名称
作者:SD
Email:
备注:转载或修改请保留此信息
Function sdGetIniInfo(ByVal iniFile As String ByVal iniSection As String) As String
If Not FileExists(iniFile) Then
Return 文件 & iniFile & 未找到请确认路径和文件名是否正确!
Exit Function
End If
Dim iniRead As New StreamReader(iniFile)
Dim iniStr As String = iniReadReadToEnd
Dim i As Integer
Dim cLine As Integer
Dim noSec As Boolean = False
Dim getValue As String =
Dim cLst
cLst = iniStrSplit(Chr())
cLine = UBound(cLst)
For i = To cLine
If cLst(i)indexof(=) > Then
If cLst(i)split(=)()trim() = iniSection Then
noSec = True
getValue = cLst(i)split(=)()trim()
Exit For
End If
End If
Next
If noSec = True Then
Return getValue
Else
Return 没有找到 & iniSection & 的设置信息!
End If
End Function
说明在引用的面页中要先引用 Imports SystemIO
EG:
setini文件内容
[Info]
name=zhuang
age=
Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
Dim name As String
name = sdGetIniInfo(ApplicationStartupPath & \setini name)
MsgBox(name)
End Sub