Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How VB.NET reads INI

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces VB.NET how to read INI, the article is very detailed, has a certain reference value, interested friends must read it!

Although it is very convenient to read XML configuration information in VB.NET, sometimes the INI file is still used in the development process, but VB.NET reading INI is not as convenient as in VB. I just wrote a function and now post it, maybe you can use it.

Function sdGetIniInfo (ByVal iniFile As String

ByVal iniSection As String) As String

If Not File.Exists (iniFile) Then

Return "File" & iniFile & "not found, please make sure the path and file name are correct!"

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 "did not find the setting information for" & iniSection & "!"

End If

End Function

Note: Imports System.IO should be referenced first in the referenced face page.

Contents of set.ini file:

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

The above is all the contents of the article "how to read INI by VB.NET". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report