-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcINIFile.cls
69 lines (50 loc) · 2.61 KB
/
cINIFile.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "cINIFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
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) As Long
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize 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 WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Private Const BufferSize As Long = 4096
Private strIniFile As String
Public Property Get File() As String
File = strIniFile
End Property
Public Property Let File(Value As String)
strIniFile = Value
End Property
Public Function GetValue(strSection As String, strKey As String) As Variant
Dim strBuffer As String
Dim lLength As Long
strBuffer = Space(BufferSize)
lLength = GetPrivateProfileString(strSection, strKey, vbNullString, strBuffer, BufferSize, strIniFile)
GetValue = Left(strBuffer, lLength)
End Function
Public Sub WriteValue(strSection As String, strKey As String, vntValue As Variant)
WritePrivateProfileString strSection, strKey, CStr(vntValue), strIniFile
End Sub
Public Function GetSection(strSection As String) As Variant
Dim strBuffer As String
Dim lLength As Long
strBuffer = Space(BufferSize)
lLength = GetPrivateProfileSection(strSection, strBuffer, BufferSize, strIniFile)
GetSection = Split(Left(strBuffer, lLength), vbNullChar)
End Function
Public Function GetSectionKeys(strSection As String) As Variant
Dim strBuffer As String
Dim lLength As Long
strBuffer = Space(BufferSize)
lLength = GetPrivateProfileString(strSection, vbNullString, vbNullString, strBuffer, BufferSize, strIniFile)
GetSectionKeys = Split(Left(strBuffer, lLength), vbNullChar)
End Function