Read and write INI file Custom function (VB)

Source: Internet
Author: User
Tags ini
function Private Declare function getprivateprofileint Lib "kernel32" Alias "Getprivateprofileinta" (ByVal Lpapplicationname as String, ByVal Lpkeyname as String, ByVal Ndefault as Long, ByVal lpFileName as String) as Long
Private Declare Function getprivateprofilestring Lib "kernel32" Alias "Getprivateprofilestringa" (ByVal Lpapplicationname As String, ByVal lpkeyname as any, ByVal Lpdefault as String, ByVal lpreturnedstring as String, ByVal NS Ize as Long, ByVal lpFileName as String) as Long
Private Declare Function writeprivateprofilestring Lib "kernel32" Alias "Writeprivateprofilestringa" (ByVal Lpapplicationname As String, ByVal lpkeyname as any, ByVal lpstring as any, ByVal lpFileName as String) as Long
Private Declare Function getwindowsdirectory Lib "kernel32" Alias "Getwindowsdirectorya" (ByVal lpbuffer as String, ByVal Nsize as long) as long

' Write INI file (string)
Public Sub Writeini (ByVal FileName As String, ByVal App as String, ByVal Key as String, ByVal strvalue as String)
Dim result as Long
result = WritePrivateProfileString (App, Key, strvalue, FileName)
End Sub
' Read integral type
Public Function Getiniint (ByVal FileName As String, ByVal App as String, ByVal Key as String) as Long
Dim result as Long
result = Getprivateprofileint (App, Key, 0, FileName)
Getiniint = result
End Function
' Read string
Public Function getinistr (ByVal FileName As String, ByVal App as String, ByVal Key as String) as String
Dim result as Long
Dim Bufferstr as String * 255
result = GetPrivateProfileString (App, Key, "", Bufferstr, Len (BUFFERSTR), FileName)
If result = 0 Then
Getinistr = ""
Else
Getinistr = Left (bufferstr, result)
End If
End Function


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.