-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.bas
356 lines (317 loc) · 9.03 KB
/
demo.bas
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
Attribute VB_Name = "demo"
Sub Demo()
Attribute Demo.VB_ProcData.VB_Invoke_Func = " \n14"
Dim wb As Workbook
Dim ws As Worksheet
Dim d As cDataTable
Dim f As cDataFactory
Dim rng As Range
Set f = New cDataFactory
Set wb = Workbooks.Add
Set ws = ActiveSheet
ws.Name = "DemoAsArray"
Set d = CreateRecords1
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoSelectFields"
Set d = DemoSelectFields
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoWhereField"
Set d = DemoWhereField
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoWhereFieldIn"
Set d = DemoWhereFieldIn
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoWhereFieldNotIn"
Set d = DemoWhereFieldNotIn
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoWhereFieldBetween"
Set d = DemoWhereFieldBetween
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoAggregateSUM"
Set d = DemoAggregateSUM
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoAggregateCOUNT"
Set d = DemoAggregateCOUNT
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoAggregateMIN"
Set d = DemoAggregateMIN
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoAggregateMAX"
Set d = DemoAggregateMAX
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoSort"
Set d = DemoSort
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoBOFEOF"
Set d = DemoBOFEOF
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoDataFactoryExcel"
Set d = DemoDataFactoryExcel
Set objrange = f.InsertDataTableToCell(Selection, d)
Set d = f.GetDataTableFromRange(objrange)
Set objrange = objrange.Offset(0, 10)
f.InsertDataTableToCell objrange, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoDuplicateField"
Set d = DemoDuplicateField
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoMoveOperations"
Set d = DemoMoveOperations
f.InsertDataTableToCell Selection, d
Set ws = wb.Worksheets.Add
ws.Name = "DemoExcludeHeader"
Set d = DemoExcludeHeader
f.InsertDataTableToCell Selection, d, True
Set ws = wb.Worksheets.Add
ws.Name = "DemoSetFieldOrder"
Set d = DemoSetFieldOrder
f.InsertDataTableToCell Selection, d
End Sub
Function CreateRecords1() As cDataTable
Attribute CreateRecords1.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As New cDataTable
Dim r As New cRecord
r.AddField "ID", 1
r.AddField "Column1", "USD"
r.AddField "Column2", 6
r.AddField "Column3", "Orange"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 2
r.AddField "Column1", "GBP"
r.AddField "Column2", 14.6
r.AddField "Column3", "Red"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 3
r.AddField "Column1", "GBP"
r.AddField "Column2", 14.3
r.AddField "Column3", "Orange"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 4
r.AddField "Column1", "GBP"
r.AddField "Column2", 7
r.AddField "Column3", "Orange"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 5
r.AddField "Column1", "USD"
r.AddField "Column2", 9
r.AddField "Column3", "Orange"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 6
r.AddField "Column1", "USD"
r.AddField "Column2", 1.3
r.AddField "Column3", "Green"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 7
r.AddField "Column1", "USD"
r.AddField "Column2", 9
r.AddField "Column3", "Green"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 8
r.AddField "Column1", "USD"
r.AddField "Column2", 80
r.AddField "Column3", "Green"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 9
r.AddField "Column1", "USD"
r.AddField "Column2", 90
r.AddField "Column3", "Red"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 10
r.AddField "Column1", "GBP"
r.AddField "Column2", 4.7
r.AddField "Column3", "Green"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 11
r.AddField "Column1", "GBP"
r.AddField "Column2", 19
r.AddField "Column3", "Orange"
d.AddRecord r
Set r = New cRecord
r.AddField "ID", 12
r.AddField "Column1", "USD"
r.AddField "Column2", 10
r.AddField "Column3", "Green"
d.AddRecord r
Set CreateRecords1 = d
End Function
Function DemoSelectFields() As cDataTable
Attribute DemoSelectFields.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Set d = CreateRecords1
Set d = d.SelectFields("ID", "Column2")
Set DemoSelectFields = d
End Function
Function DemoWhereField() As cDataTable
Attribute DemoWhereField.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Set d = CreateRecords1
Set d = d.WhereField("Column2", 14.3)
Set DemoWhereField = d
End Function
Function DemoWhereFieldIn() As cDataTable
Attribute DemoWhereFieldIn.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Set d = CreateRecords1
Set d = d.WhereFieldIn("Column2", 14.3, 80, 90)
Set DemoWhereFieldIn = d
End Function
Function DemoWhereFieldNotIn() As cDataTable
Attribute DemoWhereFieldNotIn.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Set d = CreateRecords1
Set d = d.WhereFieldNotIn("Column2", 14.3, 80, 90)
Set DemoWhereFieldNotIn = d
End Function
Function DemoWhereFieldBetween() As cDataTable
Attribute DemoWhereFieldBetween.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Set d = CreateRecords1
Set d = d.WhereFieldBetween("Column2", 7, 15)
Set DemoWhereFieldBetween = d
End Function
Function DemoAggregateSUM() As cDataTable
Attribute DemoAggregateSUM.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set d = d.SelectFields("Column1", "Column2", "Column3")
Set r = d.DefaultRecord(False)
r.UpdateField "Column2", "SUM"
Set d = d.Aggregate(r)
Set DemoAggregateSUM = d
End Function
Function DemoAggregateCOUNT() As cDataTable
Attribute DemoAggregateCOUNT.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set d = d.SelectFields("Column1", "Column2", "Column3")
Set r = d.DefaultRecord(False)
r.UpdateField "Column2", "COUNT"
Set d = d.Aggregate(r)
Set DemoAggregateCOUNT = d
End Function
Function DemoAggregateMIN() As cDataTable
Attribute DemoAggregateMIN.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set d = d.SelectFields("Column1", "Column2", "Column3")
Set r = d.DefaultRecord(False)
r.UpdateField "Column2", "MIN"
Set d = d.Aggregate(r)
Set DemoAggregateMIN = d
End Function
Function DemoAggregateMAX() As cDataTable
Attribute DemoAggregateMAX.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set d = d.SelectFields("Column1", "Column2", "Column3")
Set r = d.DefaultRecord(False)
r.UpdateField "Column2", "MAX"
Set d = d.Aggregate(r)
Set DemoAggregateMAX = d
End Function
Function DemoSort() As cDataTable
Attribute DemoSort.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set r = d.DefaultRecord(False)
r.UpdateField "Column1", "2"
r.UpdateField "Column2", "-3"
r.UpdateField "Column3", "1"
Set d = d.Sort(r)
Set DemoSort = d
End Function
Function DemoBOFEOF() As cDataTable
Attribute DemoBOFEOF.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set r = d.MoveFirst
Do Until d.EOF
r.UpdateField "Column1", d.EOF
r.UpdateField "Column2", d.BOF
r.UpdateField "Column3", d.RecordNumber
Set r = d.MoveNext
Loop
Set DemoBOFEOF = d
End Function
Function DemoDataFactoryExcel() As cDataTable
Attribute DemoDataFactoryExcel.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set DemoDataFactoryExcel = d
End Function
Function DemoDuplicateField() As cDataTable
Attribute DemoDuplicateField.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
d.AddField "Column1", "test"
Set DemoDuplicateField = d
End Function
Function DemoMoveOperations() As cDataTable
Attribute DemoMoveOperations.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
d.DeleteRecord
d.MovePrevious
d.DeleteRecord
d.MoveFirst
d.DeleteRecord
d.MoveNext
d.DeleteRecord
d.NewRecord
d.UpdateFieldValue "ID", 13
d.UpdateFieldValue "Column1", "ZAR"
d.UpdateFieldValue "Column2", 56
d.UpdateFieldValue "Column3", "Blue"
d.DeleteRecord "5"
Set DemoMoveOperations = d
End Function
Function DemoExcludeHeader() As cDataTable
Attribute DemoExcludeHeader.VB_ProcData.VB_Invoke_Func = " \n14"
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
Set DemoExcludeHeader = d
End Function
Function DemoSetFieldOrder() As cDataTable
Dim d As cDataTable
Dim r As cRecord
Set d = CreateRecords1
d.SetFieldOrder "Column3", 0
d.SetFieldOrder "ID", 12
d.SetFieldOrder "Column1", 2
d.AddField "Column4", "New", 0
d.AddField "Column0", "New", 4
Set DemoSetFieldOrder = d
End Function