Get the App
SLTechnology News&Howtos  ›  Development  › 

How VB.NET reads INI

Shulou Source: shulou.com Published: 2022-06-02 09:29:16 11月22日 Update

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!

Tags: Document content information article value potential energy interest function guy partner file name more knowledge industry information channel path process or channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL OPPO Reno Microsoft Huawei