| 'Description: Easily use Private Initialization File's (.ini) 'Where to place code: Class File ' ' GetKeyStr method ' Returns the string value of a key in an ini file or an empty string if the key is not found ' Set strFile to the ini file you want to use ' Set strSection to the section of the ini file the key is located under ' Set strKey to the name of the key who's value you want returned ' ' GetKeyInt method ' Returns the integer value of a key in an ini file or 0 if the key is not found ' Set strFile to the ini file you want to use ' Set strSection to the section of the ini file the key is located under ' Set strKey to the name of the key who's value you want returned ' ' SetKeyString method ' Sets the string value of a key in an ini file ' To set a key to an integer value, convert the number to a string first using CStr() ' Set strFile to the ini file you want to use ' Set strSection to the section of the ini file the key is located under ' Set strKey to the name of the key who's value you want to set ' Set strData to the string you want written to the key ' ' DeleteSection method ' Deletes a section and all its keys from an ini file ' Set strFile to the ini file you want to use ' Set strSection to the name of the section you want to delete ' ' DeleteKey method ' Deletes a key in the specified section ' Set strFile to the ini file you want to use ' Set strSection to the section of the ini file the key is located under ' Set strKey to the name of the key you want to delete ' ' 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 nSize As Long, ByVal lpFileName As String) Private Declare Function GetPrivateProfileInt& Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) Private Declare Function WritePrivateProfileString& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) Public Function GetKeyStr(strFile As String, strSection As String, strKey As String) Dim strInfo As String Dim lngRet As Long strInfo = String(260, " ") GetPrivateProfileString strSection, strKey, "", strInfo, 260, strFile GetKeyStr = Trim(strInfo) End Function Public Function GetKeyInt(strFile As String, strSection As String, strKey As String) GetKeyInt = GetPrivateProfileInt(strSection, strKey, 0, strFile) End Function Public Sub SetKeyString(strFile As String, strSection As String, strKey As String, strData As String) WritePrivateProfileString strSection, strKey, strData, strFile End Sub Public Sub DeleteSection(strFile As String, strSection As String) WritePrivateProfileString strSection, vbNullString, vbNullString, strFile End Sub Public Sub DeleteKey(strFile As String, strSection As String, strKey As String) WritePrivateProfileString strSection, strKey, vbNullString, strFile End Sub |
Class: CINIFile |
Express News India | Freelance ecommerce web development India