Vb. NET to read the INI file set information function Sdgetiniinfo

Source: Internet
Author: User
Tags exit ini integer read ini file split trim
Function


Although vb.net read XML configuration information is convenient, but sometimes the process of development or to use the INI file, in the vb.net read INI is not as convenient as VB, just wrote a function, now posted, perhaps you can use.


' Function name: Sdgetiniinfo
' function: Read INI file settings information
' Parameter description: Inifile-->ini file Inisection--ini the part name set in the file
' Author: SD
' Date: 2005-10-11
' Email:ztqas@126.com
' Remark: Reprint or modify please keep this information
Function Sdgetiniinfo (ByVal iniFile As String, ByVal inisection as String) as String
If not file.exists (iniFile) Then
Return "file" & IniFile & not found, make sure the path and filename 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" & inisection & "Settings information! "
End If
End Function

Description: In the referenced face page, you must first refer to the Imports System.IO

EG:

Set.ini File Contents:

[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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.