[Visual Basic] VB Source Code Recommended: A class for operating the INI file

zhaozj2021-02-08  260

[VB source recommended: a class of operation INI files] -------- CiniFile.CLS code -------------- "define a CiniFile class Option Explicit '// Private member that holds a reference to' // the path of our ini filePrivate strInI As String '// Win API DeclaresPrivate Declare Function WritePrivateProfileString _ Lib "kernel32" Alias ​​"WritePrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpString As Any, _ ByVal lpFileName As String) As LongPrivate Declare Function GetPrivateProfileString _ Lib "kernel32" Alias ​​"GetPrivateProfileStringA" _ (ByVal lpApplicationName As String, _ ByVal lpKeyName As Any, _ ByVal lpDefault As String, _ ByVal lpReturnedString As String, _ ByVal nSize As Long, _ ByVal lpFileName As String) As LongPrivate Function MakePath (ByVal strDrv As String, _ ByVal strDir As String) As String '// Makes an INI file: Guarantees a sub dirDo While Right $ ( StrDrv, 1) = "/" strDRV = Left $ (strDrv, len (strdrv) - 1) Loopdo while left $ (strdir, 1) = "/" strdir = mid $ (strdir, 2) lo op '// Return the pathMakePath = strDrv & "/" & strDirEnd FunctionPublic Sub CreateIni (strDrv As String, strDir As String)' // Make a new ini filestrInI = MakePath (strDrv, strDir) End SubPublic Sub WriteFile (strSection As String , _strKey As String, _strValue As String) '// Write to strINIWritePrivateProfileString strSection, _ strKey, strValue, strInIEnd SubPublic Function GetFile (strSection As String, _ strKey As String) As String Dim strTmp As String Dim lngRet As String strTmp = String $ (100, CHR (32)) lngret = getprivateprofilestring (strsection, _ strkey, ""

转载请注明原文地址:https://www.9cbs.com/read-765.html

New Post(0)