Class for read/write operations on. ini files using VB.net

Source: Internet
Author: User

Option explicit on

Module ini
'Ini Cont. bas ver 1.0 + A ini '==================================== ==========================================
'Getintfromini (sectionname, keyname, defaultvalue, inipath)
'
'Sectionname: node name

'Keyname: configuration item name
'Defaultvalue: Default Value

'Inipath: ini configuration file path

'
'================================================ ==================================

// Declare the system function for retrieving the value of a configuration item of the int type from the ini configuration file
Private declare function getprivateprofileint lib "Kernel32" alias "getprivateprofileinta" (byval lpappname as string, byval lpkeyname as string, byval ndefault as integer, byval lpfilename as string) as integer

// Declare a system function that obtains the value of a string-type configuration item from the ini configuration file
Private declare function getprivateprofilestring lib "Kernel32" alias "inline" (byval lpappname as string, byval lpkeyname as string, byval lpdefault as string, byval lpreturnedstring as string, byval nsize as integer, byval lpename
As string) as integer

// Declare the system function that writes the value of a string-type configuration item to the ini configuration file.

Private declare function writeprivateprofilestring lib "Kernel32" alias "writeprivateprofilestringa" (byval lpappname as string, byval lpkeyname as string, byval lpstring as string, byval lpfilename as string) as integer

// Obtain the value of the int type configuration item from the ini configuration file

Public Function getintfromini (byval sectionname as string, byval keyname as string, byval defaultvalue as integer, byval inipath as string) as integer

Getintfromini = getprivateprofileint (sectionname, keyname, defaultvalue, inipath)
End Function

// Obtain the value of a string-type configuration item from the ini configuration file
Public Function getstrfromini (byval sectionname as string, byval keyname as string, byval defaultvalue as string, byval inipath as string) as string
Dim buffer as string

Dim RC as integer

Buffer = space (0, 256)

Rc = getprivateprofilestring (sectionname, keyname, defaultvalue, buffer, buffer. length, inipath)

Getstrfromini = left (buffer, instr (buffer, vbnullchar)-1)
End Function

// Write the string-type configuration item value to the ini configuration file

Public Function writestrini (byval sectionname as string, byval keyname as string, byval setvalue as string, byval inipath as string) as integer
Dim RC as integer

Rc = writeprivateprofilestring (sectionname, keyname, setvalue, inipath)

If RC then
Rc = 1
End if
Writestrini = RC
End Function

End Module

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.