新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
簡單講述VB.NET讀取INI
VB.NET還是比較常用的,于是我研究了一下VB.NET讀取INI,在這里拿出來和大家分享一下,希望對大家有用。

成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比資興網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式資興網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋資興地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。
雖然VB.NET中讀取XML配置信息很方便,但有時開發(fā)的過程中還是要用到INI文件,VB.NET讀取INI卻不像VB中那么方便了,剛才寫了個函數(shù),現(xiàn)貼出來,也許各位能用得上。
- Function sdGetIniInfo(ByVal iniFile As String,
ByVal iniSection As String) As String- If Not File.Exists(iniFile) Then
- Return "文件 " & iniFile & " 未找到,請確認(rèn)路徑和文件名是否正確!"
- 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 & " 的設(shè)置信息!"
- End If
- End Function
說明:在引用的面頁中要先引用 Imports System.IO
set.ini文件內(nèi)容:
- 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讀取INI。
名稱欄目:簡單講述VB.NET讀取INI
文章網(wǎng)址:http://www.dlmjj.cn/article/djeeooc.html


咨詢
建站咨詢
