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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Collect" script:language="StarBasic">Option Compatible
Option ClassModule
Option Explicit
REM MODULE NAME <> COLLECTION (seems a reserved name ?)
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CLASS ROOT FIELDS ---
REM -----------------------------------------------------------------------------------------------------------------------
Private _Type As String ' Must be COLLECTION
Private _CollType As String
Private _ParentType As String
Private _ParentName As String ' Name or shortcut
Private _Count As Long
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CONSTRUCTORS / DESTRUCTORS ---
REM -----------------------------------------------------------------------------------------------------------------------
Private Sub Class_Initialize()
_Type = OBJCOLLECTION
_CollType = ""
_ParentType = ""
_ParentName = ""
_Count = 0
End Sub ' Constructor
REM -----------------------------------------------------------------------------------------------------------------------
'Private Sub Class_Terminate()
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CLASS GET/LET/SET PROPERTIES ---
REM -----------------------------------------------------------------------------------------------------------------------
Property Get Count() As Long
Count = _PropertyGet("Count")
End Property ' Count (get)
REM -----------------------------------------------------------------------------------------------------------------------
Property Get Item(ByVal Optional pvItem As Variant) As Variant
'Return property value.
'pvItem either numeric index or property name
Const cstThisSub = "Collection.getItem"
Utils._SetCalledSub(cstThisSub)
If IsMissing(pvItem) Then Call _TraceArguments()
If Not Utils._CheckArgument(pvItem, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
Dim vNames() As Variant, oProperty As Object
Set Item = Nothing
Select Case _CollType
Case COLLALLDIALOGS
Set Item = Application.AllDialogs(pvItem)
Case COLLALLFORMS
Set Item = Application.AllForms(pvItem)
Case COLLCONTROLS
Select Case _ParentType
Case OBJCONTROL, OBJSUBFORM
Set Item = getObject(_ParentName).Controls(pvItem)
Case OBJDIALOG
Set Item = Application.AllDialogs(_ParentName).Controls(pvItem)
Case OBJFORM
Set Item = Application.Forms(_ParentName).Controls(pvItem)
Case OBJOPTIONGROUP
' NOT SUPPORTED
End Select
Case COLLFORMS
Set Item = Application.Forms(pvItem)
Case COLLFIELDS
Select Case _ParentType
Case OBJQUERYDEF
Set Item = Application.CurrentDb().QueryDefs(_ParentName).Fields(pvItem)
Case OBJRECORDSET
Set Item = Application.CurrentDb().Recordsets(_ParentName).Fields(pvItem)
Case OBJTABLEDEF
Set Item = Application.CurrentDb().TableDefs(_ParentName).Fields(pvItem)
End Select
Case COLLPROPERTIES
Select Case _ParentType
Case OBJCONTROL, OBJSUBFORM
Set Item = getObject(_ParentName).Properties(pvItem)
Case OBJDATABASE
Set Item = Application.CurrentDb().Properties(pvItem)
Case OBJDIALOG
Set Item = Application.AllDialogs(_ParentName).Properties(pvItem)
Case OBJFIELD
vNames() = Split(_ParentName, "/")
Select Case vNames(0)
Case OBJQUERYDEF
Set Item = Application.CurrentDb().QueryDefs(vNames(1)).Fields(vNames(2)).Properties(pvItem)
Case OBJRECORDSET
Set Item = Application.CurrentDb().Recordsets(vNames(1)).Fields(vNames(2)).Properties(pvItem)
Case OBJTABLEDEF
Set Item = Application.CurrentDb().TableDefs(vNames(1)).Fields(vNames(2)).Properties(pvItem)
End Select
Case OBJFORM
Set Item = Application.Forms(_ParentName).Properties(pvItem)
Case OBJQUERYDEF
Set Item = Application.CurrentDb().QueryDefs(_ParentName).Properties(pvItem)
Case OBJRECORDSET
Set Item = Application.CurrentDb().Recordsets(_ParentName).Properties(pvItem)
Case OBJTABLEDEF
Set Item = Application.CurrentDb().TableDefs(_ParentName).Properties(pvItem)
Case OBJCOLLECTION, OBJEVENT, OBJOPTIONGROUP
' NOT SUPPORTED
End Select
Case COLLQUERYDEFS
Set Item = Application.CurrentDb().QueryDefs(pvItem)
Case COLLRECORDSETS
Set Item = Application.CurrentDb().Recordsets(pvItem)
Case COLLTABLEDEFS
Set Item = Application.CurrentDb().TableDefs(pvItem)
Case Else
End Select
Exit_Function:
Exit Property
Error_Function:
TraceError(TRACEABORT, Err, Utils._CalledSub(), Erl)
Set Item = Nothing
GoTo Exit_Function
End Property ' V0.9.5
REM -----------------------------------------------------------------------------------------------------------------------
Property Get ObjectType() As String
ObjectType = _PropertyGet("ObjectType")
End Property ' ObjectType (get)
REM -----------------------------------------------------------------------------------------------------------------------
Public Function Properties(ByVal Optional pvIndex As Variant) As Variant
' Return
' a Collection object if pvIndex absent
' a Property object otherwise
Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String
vPropertiesList = _PropertiesList()
sObject = Utils._PCase(_Type)
If IsMissing(pvIndex) Then
vProperty = PropertiesGet._Properties(sObject, _ParentName, vPropertiesList)
Else
vProperty = PropertiesGet._Properties(sObject, _ParentName, vPropertiesList, pvIndex)
vProperty._Value = _PropertyGet(vPropertiesList(pvIndex))
End If
Exit_Function:
Set Properties = vProperty
Exit Function
End Function ' Properties
REM -----------------------------------------------------------------------------------------------------------------------
REM --- CLASS METHODS ---
REM -----------------------------------------------------------------------------------------------------------------------
Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant
' Return property value of psProperty property name
Utils._SetCalledSub("Collection.getProperty")
If IsMissing(pvProperty) Then Call _TraceArguments()
getProperty = _PropertyGet(pvProperty)
Utils._ResetCalledSub("Collection.getProperty")
End Function ' getProperty
REM -----------------------------------------------------------------------------------------------------------------------
Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean
' Return True if object has a valid property called pvProperty (case-insensitive comparison !)
If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty)
Exit Function
End Function ' hasProperty
REM -----------------------------------------------------------------------------------------------------------------------
REM --- PRIVATE FUNCTIONS ---
REM -----------------------------------------------------------------------------------------------------------------------
Private Function _PropertiesList() As Variant
_PropertiesList = Array("Count", "ObjectType")
End Function ' _PropertiesList
REM -----------------------------------------------------------------------------------------------------------------------
Private Function _PropertyGet(ByVal psProperty As String) As Variant
' Return property value of the psProperty property name
If _ErrorHandler() Then On Local Error Goto Error_Function
Utils._SetCalledSub("Collection.get" & psProperty)
_PropertyGet = Nothing
Select Case UCase(psProperty)
Case UCase("Count")
_PropertyGet = _Count
Case UCase("ObjectType")
_PropertyGet = _Type
Case Else
Goto Trace_Error
End Select
Exit_Function:
Utils._ResetCalledSub("Collection.get" & psProperty)
Exit Function
Trace_Error:
TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(), 0, 1, psProperty)
_PropertyGet = Nothing
Goto Exit_Function
Error_Function:
TraceError(TRACEABORT, Err, "Collection._PropertyGet", Erl)
_PropertyGet = Nothing
GoTo Exit_Function
End Function ' _PropertyGet
</script:module>
|