summaryrefslogtreecommitdiffstats
path: root/wizards/source/scriptforge/SF_Dictionary.xba
blob: 22ada5148e2afbb2a822c02af66e111f657c9d9b (plain)
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
<?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="SF_Dictionary" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
REM ===			The ScriptForge library and its associated libraries are part of the LibreOffice project.				===
REM ===					Full documentation is available on https://help.libreoffice.org/								===
REM =======================================================================================================================

Option Compatible
Option ClassModule

Option Explicit

&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
&apos;&apos;&apos;	SF_Dictionary
&apos;&apos;&apos;	=============
&apos;&apos;&apos;		Class for management of dictionaries
&apos;&apos;&apos;		A dictionary is a collection of key-item pairs
&apos;&apos;&apos;			The key is a not case-sensitive string
&apos;&apos;&apos;			Items may be of any type
&apos;&apos;&apos;		Keys, items can be retrieved, counted, etc.
&apos;&apos;&apos;
&apos;&apos;&apos;		The implementation is based on
&apos;&apos;&apos;			- one collection mapping keys and entries in the array
&apos;&apos;&apos;			- one 1-column array: key + data
&apos;&apos;&apos;
&apos;&apos;&apos;		Why a Dictionary class beside the builtin Collection class ?
&apos;&apos;&apos;			A standard Basic collection does not support the retrieval of the keys
&apos;&apos;&apos;			Additionally it may contain only simple data (strings, numbers, ...)
&apos;&apos;&apos;
&apos;&apos;&apos;		Service instantiation example:
&apos;&apos;&apos;			Dim myDict As Variant
&apos;&apos;&apos;			myDict = CreateScriptService(&quot;Dictionary&quot;)		&apos;	Once per dictionary
&apos;&apos;&apos;
&apos;&apos;&apos;		Detailed user documentation:
&apos;&apos;&apos;			https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_dictionary.html?DbPAR=BASIC
&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;

REM ================================================================== EXCEPTIONS

Const DUPLICATEKEYERROR			=	&quot;DUPLICATEKEYERROR&quot;		&apos;	Key exists already
Const UNKNOWNKEYERROR			=	&quot;UNKNOWNKEYERROR&quot;		&apos;	Key not found
Const INVALIDKEYERROR			=	&quot;INVALIDKEYERROR&quot;		&apos;	Key contains only spaces

REM ============================================================= PRIVATE MEMBERS

&apos;	Defines an entry in the MapItems array
Type ItemMap
	Key						As String
	Value					As Variant
End Type

Private [Me]				As Object
Private [_Parent]			As Object
Private ObjectType			As String		&apos; Must be &quot;DICTIONARY&quot;
Private ServiceName			As String
Private MapKeys				As Variant		&apos; To retain the original keys
Private MapItems			As Variant		&apos; Array of ItemMaps
Private _MapSize			As Long			&apos; Total number of entries in the dictionary
Private _MapRemoved			As Long			&apos; Number of inactive entries in the dictionary

REM ===================================================== CONSTRUCTOR/DESTRUCTOR

REM -----------------------------------------------------------------------------
Private Sub Class_Initialize()
	Set [Me] = Nothing
	Set [_Parent] = Nothing
	ObjectType = &quot;DICTIONARY&quot;
	ServiceName = &quot;ScriptForge.Dictionary&quot;
	Set MapKeys = New Collection
	Set MapItems = Array()
	_MapSize = 0
	_MapRemoved = 0
End Sub		&apos;	ScriptForge.SF_Dictionary Constructor

REM -----------------------------------------------------------------------------
Private Sub Class_Terminate()
	Call Class_Initialize()
End Sub		&apos;	ScriptForge.SF_Dictionary Destructor

REM -----------------------------------------------------------------------------
Public Function Dispose() As Variant
	RemoveAll()
	Set Dispose = Nothing
End Function	&apos;	ScriptForge.SF_Dictionary Explicit destructor

REM ================================================================== PROPERTIES

REM -----------------------------------------------------------------------------
Property Get Count() As Long
&apos;&apos;&apos;	Actual number of entries in the dictionary
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		myDict.Count

	Count = _PropertyGet(&quot;Count&quot;)

End Property	&apos;	ScriptForge.SF_Dictionary.Count

REM -----------------------------------------------------------------------------
Public Function Item(Optional ByVal Key As Variant) As Variant
&apos;&apos;&apos;	Return the value of the item related to Key
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Key: the key value (string)
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		Empty if not found, otherwise the found value
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		myDict.Item(&quot;ThisKey&quot;)
&apos;&apos;&apos;	NB: defined as a function to not disrupt the Basic IDE debugger

	Item = _PropertyGet(&quot;Item&quot;, Key)

End Function	&apos;	ScriptForge.SF_Dictionary.Item

REM -----------------------------------------------------------------------------
Property Get Items() as Variant
&apos;&apos;&apos;	Return the list of Items as a 1D array
&apos;&apos;&apos;	The Items and Keys properties return their respective contents in the same order
&apos;&apos;&apos;		The order is however not necessarily identical to the creation sequence
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The array is empty if the dictionary is empty
&apos;&apos;&apos;	Examples
&apos;&apos;&apos;		a = myDict.Items
&apos;&apos;&apos;		For Each b In a ...

	Items = _PropertyGet(&quot;Items&quot;)

End Property	&apos;	ScriptForge.SF_Dictionary.Items

REM -----------------------------------------------------------------------------
Property Get Keys() as Variant
&apos;&apos;&apos;	Return the list of keys as a 1D array
&apos;&apos;&apos;	The Keys and Items properties return their respective contents in the same order
&apos;&apos;&apos;		The order is however not necessarily identical to the creation sequence
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The array is empty if the dictionary is empty
&apos;&apos;&apos;	Examples
&apos;&apos;&apos;		a = myDict.Keys
&apos;&apos;&apos;		For each b In a ...

	Keys = _PropertyGet(&quot;Keys&quot;)

End Property	&apos;	ScriptForge.SF_Dictionary.Keys

REM ===================================================================== METHODS

REM -----------------------------------------------------------------------------
Public Function Add(Optional ByVal Key As Variant _
						, Optional ByVal Item As Variant _
						) As Boolean
&apos;&apos;&apos;	Add a new key-item pair into the dictionary
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Key: must not yet exist in the dictionary
&apos;&apos;&apos;		Item: any value, including an array, a Basic object, a UNO object, ...
&apos;&apos;&apos;	Returns: True if successful
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		DUPLICATEKEYERROR: such a key exists already
&apos;&apos;&apos;		INVALIDKEYERROR: zero-length string or only spaces
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		myDict.Add(&quot;NewKey&quot;, NewValue)

Dim oItemMap As ItemMap			&apos;	New entry in the MapItems array
Const cstThisSub = &quot;Dictionary.Add&quot;
Const cstSubArgs = &quot;Key, Item&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Add = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(Key, &quot;Key&quot;, V_STRING) Then GoTo Catch
		If IsArray(Item) Then
			If Not SF_Utils._ValidateArray(Item, &quot;Item&quot;) Then GoTo Catch
		Else
			If Not SF_Utils._Validate(Item, &quot;Item&quot;) Then GoTo Catch
		End If
	End If
	If Key = Space(Len(Key)) Then GoTo CatchInvalid
	If Exists(Key) Then GoTo CatchDuplicate

Try:
	_MapSize = _MapSize + 1
	MapKeys.Add(_MapSize, Key)
	oItemMap.Key = Key
	oItemMap.Value = Item
	ReDim Preserve MapItems(1 To _MapSize)
	MapItems(_MapSize) = oItemMap
	Add = True

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchDuplicate:
	SF_Exception.RaiseFatal(DUPLICATEKEYERROR, &quot;Key&quot;, Key)
	GoTo Finally
CatchInvalid:
	SF_Exception.RaiseFatal(INVALIDKEYERROR, &quot;Key&quot;)
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.Add

REM -----------------------------------------------------------------------------
Public Function ConvertToArray() As Variant
&apos;&apos;&apos;	Store the content of the dictionary in a 2-columns array:
&apos;&apos;&apos;	Key stored in 1st column, Item stored in 2nd
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		a zero-based 2D array(0:Count - 1, 0:1)
&apos;&apos;&apos;		an empty array if the dictionary is empty

Dim vArray As Variant		&apos;	Return value
Dim sKey As String			&apos;	Tempry key
Dim vKeys As Variant		&apos;	Array of keys
Dim lCount As Long			&apos;	Counter
Const cstThisSub = &quot;Dictionary.ConvertToArray&quot;
Const cstSubArgs = &quot;&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

Check:
	SF_Utils._EnterFunction(cstThisSub, cstSubArgs)

Try:
	vArray = Array()
	If Count = 0 Then
	Else
		ReDim vArray(0 To Count - 1, 0 To 1)
		lCount = -1
		vKeys = Keys
		For Each sKey in vKeys
			lCount = lCount + 1
			vArray(lCount, 0) = sKey
			vArray(lCount, 1) = Item(sKey)
		Next sKey
	End If
		
Finally:
	ConvertToArray = vArray()
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.ConvertToArray

REM -----------------------------------------------------------------------------
Public Function ConvertToJson(ByVal Optional Indent As Variant) As Variant
&apos;&apos;&apos;	Convert the content of the dictionary to a JSON string
&apos;&apos;&apos;	JSON = JavaScript Object Notation: https://en.wikipedia.org/wiki/JSON
&apos;&apos;&apos;	Limitations
&apos;&apos;&apos;		Allowed item types: String, Boolean, numbers, Null and Empty
&apos;&apos;&apos;		Arrays containing above types are allowed
&apos;&apos;&apos;		Dates are converted into strings (not within arrays)
&apos;&apos;&apos;		Other types are converted to their string representation (cfr. SF_String.Represent)
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Indent:
&apos;&apos;&apos;			If indent is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level.
&apos;&apos;&apos;			An indent level &lt;= 0 will only insert newlines.
&apos;&apos;&apos;			&quot;&quot;, (the default) selects the most compact representation.
&apos;&apos;&apos;			Using a positive integer indent indents that many spaces per level.
&apos;&apos;&apos;			If indent is a string (such as Chr(9)), that string is used to indent each level.
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		the JSON string
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		myDict.Add(&quot;p0&quot;, 12.5)
&apos;&apos;&apos;		myDict.Add(&quot;p1&quot;, &quot;a string àé&quot;&quot;ê&quot;)
&apos;&apos;&apos;		myDict.Add(&quot;p2&quot;, DateSerial(2020,9,28))
&apos;&apos;&apos;		myDict.Add(&quot;p3&quot;, True)
&apos;&apos;&apos;		myDict.Add(&quot;p4&quot;, Array(1,2,3))
&apos;&apos;&apos;		MsgBox a.ConvertToJson()	&apos;	{&quot;p0&quot;: 12.5, &quot;p1&quot;: &quot;a string \u00e0\u00e9\&quot;\u00ea&quot;, &quot;p2&quot;: &quot;2020-09-28&quot;, &quot;p3&quot;: true, &quot;p4&quot;: [1, 2, 3]}

Dim sJson As String				&apos;	Return value
Dim vArray As Variant			&apos;	Array of property values
Dim oPropertyValue As Object	&apos;	com.sun.star.beans.PropertyValue
Dim sKey As String				&apos;	Tempry key
Dim vKeys As Variant			&apos;	Array of keys
Dim vItem As Variant			&apos;	Tempry item
Dim iVarType As Integer			&apos;	Extended VarType
Dim lCount As Long				&apos;	Counter
Dim vIndent As Variant			&apos;	Python alias of Indent
Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Dictionary__ConvertToJson&quot;

Const cstThisSub = &quot;Dictionary.ConvertToJson&quot;
Const cstSubArgs = &quot;[Indent=Null]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

Check:
	If IsMissing(Indent) Or IsEmpty(INDENT) Then Indent = &quot;&quot;
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(Indent, &quot;Indent&quot;, Array(V_STRING, V_NUMERIC)) Then GoTo Finally
	End If
	sJson = &quot;&quot;

Try:
	vArray = Array()
	If Count = 0 Then
	Else
		ReDim vArray(0 To Count - 1)
		lCount = -1
		vKeys = Keys
		For Each sKey in vKeys
			&apos;	Check item type
			vItem = Item(sKey)
			iVarType = SF_Utils._VarTypeExt(vItem)
			Select Case iVarType
				Case V_STRING, V_BOOLEAN, V_NUMERIC, V_NULL, V_EMPTY
				Case V_DATE
					vItem = SF_Utils._CDateToIso(vItem)
				Case &gt;= V_ARRAY
				Case Else
					vItem = SF_Utils._Repr(vItem)
			End Select
			&apos;	Build in each array entry a (Name, Value) pair
			Set oPropertyValue = SF_Utils._MakePropertyValue(sKey, vItem)
			lCount = lCount + 1
			Set vArray(lCount) = oPropertyValue
		Next sKey
	End If

	&apos;Pass array to Python script for the JSON conversion
	With ScriptForge.SF_Session
		vIndent = Indent
		If VarType(Indent) = V_STRING Then
			If Len(Indent) = 0 Then vIndent = Null
		End If
		sJson = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper, vArray, vIndent)
	End With
		
Finally:
	ConvertToJson = sJson
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.ConvertToJson

REM -----------------------------------------------------------------------------
Public Function ConvertToPropertyValues() As Variant
&apos;&apos;&apos;	Store the content of the dictionary in an array of PropertyValues
&apos;&apos;&apos;	Key stored in Name, Item stored in Value
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		a zero-based 1D array(0:Count - 1). Each entry is a com.sun.star.beans.PropertyValue
&apos;&apos;&apos;			Name: the key in the dictionary
&apos;&apos;&apos;			Value:
&apos;&apos;&apos;				Dates are converted to UNO dates
&apos;&apos;&apos;				Empty arrays are replaced by Null
&apos;&apos;&apos;		an empty array if the dictionary is empty

Dim vArray As Variant			&apos;	Return value
Dim oPropertyValue As Object	&apos;	com.sun.star.beans.PropertyValue
Dim sKey As String				&apos;	Tempry key
Dim vKeys As Variant		&apos;	Array of keys
Dim lCount As Long				&apos;	Counter
Const cstThisSub = &quot;Dictionary.ConvertToPropertyValues&quot;
Const cstSubArgs = &quot;&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

Check:
	SF_Utils._EnterFunction(cstThisSub, cstSubArgs)

Try:
	vArray = Array()
	If Count = 0 Then
	Else
		ReDim vArray(0 To Count - 1)
		lCount = -1
		vKeys = Keys
		For Each sKey in vKeys
			&apos;	Build in each array entry a (Name, Value) pair
			Set oPropertyValue = SF_Utils._MakePropertyValue(sKey, Item(sKey))
			lCount = lCount + 1
			Set vArray(lCount) = oPropertyValue
		Next sKey
	End If
		
Finally:
	ConvertToPropertyValues = vArray()
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.ConvertToPropertyValues

REM -----------------------------------------------------------------------------
Public Function Exists(Optional ByVal Key As Variant) As Boolean
&apos;&apos;&apos;	Determine if a key exists in the dictionary
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Key: the key value (string)
&apos;&apos;&apos;	Returns: True if key exists
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		If myDict.Exists(&quot;SomeKey&quot;) Then &apos; don&apos;t add again

Dim vItem As Variant		&apos;	Item part in MapKeys
Const cstThisSub = &quot;Dictionary.Exists&quot;
Const cstSubArgs = &quot;Key&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Exists = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(Key, &quot;Key&quot;, V_STRING) Then GoTo Catch
	End If

Try:
	&apos;	Dirty but preferred to go through whole collection
	On Local Error GoTo NotFound
	vItem = MapKeys(Key)
	NotFound:
		Exists = ( Not ( Err = 5 ) And vItem &gt; 0 )
		On Local Error GoTo 0

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.Exists

REM -----------------------------------------------------------------------------
Public Function GetProperty(Optional ByVal PropertyName As Variant _
								, Optional ByVal Key As Variant _
								) As Variant
&apos;&apos;&apos;	Return the actual value of the given property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		PropertyName: the name of the property as a string
&apos;&apos;&apos;		Key: mandatory if PropertyName = &quot;Item&quot;, ignored otherwise
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The actual value of the property
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		ARGUMENTERROR		The property does not exist
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		myDict.GetProperty(&quot;Count&quot;)

Const cstThisSub = &quot;Dictionary.GetProperty&quot;
Const cstSubArgs = &quot;PropertyName, [Key]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	GetProperty = Null

Check:
	If IsMissing(Key) Or IsEmpty(Key) Then Key = &quot;&quot;
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
	End If

Try:
	GetProperty = _PropertyGet(PropertyName, Key)

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.GetProperty

REM -----------------------------------------------------------------------------
Public Function ImportFromJson(Optional ByVal InputStr As Variant _
											, Optional ByVal Overwrite As Variant _
											) As Boolean
&apos;&apos;&apos;	Adds the content of a Json string into the current dictionary
&apos;&apos;&apos;	JSON = JavaScript Object Notation: https://en.wikipedia.org/wiki/JSON
&apos;&apos;&apos;	Limitations
&apos;&apos;&apos;		The JSON string may contain numbers, strings, booleans, null values and arrays containing those types
&apos;&apos;&apos;		It must not contain JSON objects, i.e. sub-dictionaries
&apos;&apos;&apos;	An attempt is made to convert strings to dates if they fit one of next patterns:
&apos;&apos;&apos;		YYYY-MM-DD, HH:MM:SS or YYYY-MM-DD HH:MM:SS
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		InputStr: the json string to import
&apos;&apos;&apos;		Overwrite: when True entries with same name may exist in the dictionary and their values are overwritten
&apos;&apos;&apos;			Default = False
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if successful
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		DUPLICATEKEYERROR: such a key exists already
&apos;&apos;&apos;		INVALIDKEYERROR: zero-length string or only spaces
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim s As String
&apos;&apos;&apos;		s = &quot;{&apos;firstName&apos;: &apos;John&apos;,&apos;lastName&apos;: &apos;Smith&apos;,&apos;isAlive&apos;: true,&apos;age&apos;: 66, &apos;birth&apos;:  &apos;1954-09-28 20:15:00&apos;&quot; _
&apos;&apos;&apos;			&amp; &quot;,&apos;address&apos;: {&apos;streetAddress&apos;: &apos;21 2nd Street&apos;,&apos;city&apos;: &apos;New York&apos;,&apos;state&apos;: &apos;NY&apos;,&apos;postalCode&apos;: &apos;10021-3100&apos;}&quot; _
&apos;&apos;&apos;			&amp; &quot;,&apos;phoneNumbers&apos;: [{&apos;type&apos;: &apos;home&apos;,&apos;number&apos;: &apos;212 555-1234&apos;},{&apos;type&apos;: &apos;office&apos;,&apos;number&apos;: &apos;646 555-4567&apos;}]&quot; _
&apos;&apos;&apos;			&amp; &quot;,&apos;children&apos;: [&apos;Q&apos;,&apos;M&apos;,&apos;G&apos;,&apos;T&apos;],&apos;spouse&apos;: null}&quot;
&apos;&apos;&apos;		s = Replace(s, &quot;&apos;&quot;, &quot;&quot;&quot;&quot;)
&apos;&apos;&apos;		myDict.ImportFromJson(s, OverWrite := True)
&apos;&apos;&apos;			&apos;	The (sub)-dictionaries &quot;address&quot; and &quot;phoneNumbers(0) and (1) are reduced to Empty	

Dim bImport As Boolean			&apos;	Return value
Dim vArray As Variant			&apos;	JSON string converted to array
Dim vArrayEntry As Variant		&apos;	A single entry in vArray
Dim vKey As Variant				&apos;	Tempry key
Dim vItem As Variant			&apos;	Tempry item
Dim bExists As Boolean			&apos;	True when an entry exists
Dim dDate As Date				&apos;	String converted to Date
Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Dictionary__ImportFromJson&quot;

Const cstThisSub = &quot;Dictionary.ImportFromJson&quot;
Const cstSubArgs = &quot;InputStr, [Overwrite=False]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bImport = False

Check:
	If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(InputStr, &quot;InputStr&quot;, V_STRING) Then GoTo Finally
		If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, V_BOOLEAN) Then GoYo Finally
	End If

Try:
	With ScriptForge.SF_Session
		vArray = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper, InputStr)
	End With
	If Not IsArray(vArray) Then GoTo Finally	&apos;	Conversion error or nothing to do

	&apos;	vArray = Array of subarrays = 2D DataArray (cfr. Calc)
	For Each vArrayEntry In vArray
		vKey = vArrayEntry(0)
		If VarType(vKey) = V_STRING Then	&apos;	Else skip
			vItem = vArrayEntry(1)
			If Overwrite Then bExists = Exists(vKey) Else bExists = False
			&apos;	When the item matches a date pattern, convert it to a date
			If VarType(vItem) = V_STRING Then
				dDate = SF_Utils._CStrToDate(vItem)
				If dDate &gt; -1 Then vItem = dDate
			End If
			If bExists Then
				ReplaceItem(vKey, vItem)
			Else
				Add(vKey, vItem)	&apos;	Key controls are done in Add
			End If
		End If
	Next vArrayEntry

	bImport = True

Finally:
	ImportFromJson = bImport
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.ImportFromJson

REM -----------------------------------------------------------------------------
Public Function ImportFromPropertyValues(Optional ByVal PropertyValues As Variant _
											, Optional ByVal Overwrite As Variant _
											) As Boolean
&apos;&apos;&apos;	Adds the content of an array of PropertyValues into the current dictionary
&apos;&apos;&apos;	Names contain Keys, Values contain Items
&apos;&apos;&apos;	UNO dates are replaced by Basic dates
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		PropertyValues: a zero-based 1D array. Each entry is a com.sun.star.beans.PropertyValue
&apos;&apos;&apos;		Overwrite: when True entries with same name may exist in the dictionary and their values are overwritten
&apos;&apos;&apos;			Default = False
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if successful
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		DUPLICATEKEYERROR: such a key exists already
&apos;&apos;&apos;		INVALIDKEYERROR: zero-length string or only spaces

Dim bImport As Boolean			&apos;	Return value
Dim oPropertyValue As Object	&apos;	com.sun.star.beans.PropertyValue
Dim vItem As Variant			&apos;	Tempry item
Dim sObjectType As String		&apos;	UNO object type of dates
Dim bExists As Boolean			&apos;	True when an entry exists
Const cstThisSub = &quot;Dictionary.ImportFromPropertyValues&quot;
Const cstSubArgs = &quot;PropertyValues, [Overwrite=False]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bImport = False

Check:
	If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If IsArray(PropertyValues) Then
			If Not SF_Utils._ValidateArray(PropertyValues, &quot;PropertyValues&quot;, 1, V_OBJECT, True) Then GoTo Finally
		Else
			If Not SF_Utils._Validate(PropertyValues, &quot;PropertyValues&quot;, V_OBJECT) Then GoTo Finally
		End If
		If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, V_BOOLEAN) Then GoYo Finally
	End If

Try:
	If Not IsArray(PropertyValues) Then PropertyValues = Array(PropertyValues)
	With oPropertyValue
		For Each oPropertyValue In PropertyValues
			If Overwrite Then bExists = Exists(.Name) Else bExists = False
			If SF_Session.UnoObjectType(oPropertyValue) = &quot;com.sun.star.beans.PropertyValue&quot; Then
				If IsUnoStruct(.Value) Then
					sObjectType = SF_Session.UnoObjectType(.Value)
					Select Case sObjectType
						Case &quot;com.sun.star.util.DateTime&quot;	:	vItem = CDateFromUnoDateTime(.Value)
						Case &quot;com.sun.star.util.Date&quot;		:	vItem = CDateFromUnoDate(.Value)
						Case &quot;com.sun.star.util.Time&quot;		:	vItem = CDateFromUnoTime(.Value)
						Case Else							:	vItem = .Value
					End Select
				Else
					vItem = .Value
				End If
				If bExists Then
					ReplaceItem(.Name, vItem)
				Else
					Add(.Name, vItem)	&apos;	Key controls are done in Add
				End If
			End If
		Next oPropertyValue
	End With
	bImport = True

Finally:
	ImportFromPropertyValues = bImport
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.ImportFromPropertyValues

REM -----------------------------------------------------------------------------
Public Function Methods() As Variant
&apos;&apos;&apos;	Return the list or methods of the Dictionary class as an array

	Methods = Array( _
					&quot;Add&quot; _
					, &quot;ConvertToArray&quot; _
					, &quot;ConvertToJson&quot; _
					, &quot;ConvertToPropertyValues&quot; _
					, &quot;Exists&quot; _
					, &quot;ImportFromJson&quot; _
					, &quot;ImportFromPropertyValues&quot; _
					, &quot;Remove&quot; _
					, &quot;RemoveAll&quot; _
					, &quot;ReplaceItem&quot; _
					, &quot;ReplaceKey&quot; _
					)

End Function	&apos;	ScriptForge.SF_Dictionary.Methods

REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
&apos;&apos;&apos;	Return the list or properties of the Dictionary class as an array

	Properties = Array( _
					&quot;Count&quot; _
					, &quot;Item&quot; _
					, &quot;Items&quot; _
					, &quot;Keys&quot; _
					)

End Function	&apos;	ScriptForge.SF_Dictionary.Properties

REM -----------------------------------------------------------------------------
Public Function Remove(Optional ByVal Key As Variant) As Boolean
&apos;&apos;&apos;	Remove an existing dictionary entry based on its key
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Key: must exist in the dictionary
&apos;&apos;&apos;	Returns: True if successful
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNKEYERROR: the key does not exist
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		myDict.Remove(&quot;OldKey&quot;)

Dim lIndex As Long				&apos;	To remove entry in the MapItems array
Const cstThisSub = &quot;Dictionary.Remove&quot;
Const cstSubArgs = &quot;Key&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Remove = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(Key, &quot;Key&quot;, V_STRING) Then GoTo Catch
	End If
	If Not Exists(Key) Then GoTo CatchUnknown

Try:
	lIndex = MapKeys.Item(Key)
	MapKeys.Remove(Key)
	Erase MapItems(lIndex)	&apos;	Is now Empty
	_MapRemoved = _MapRemoved + 1
	Remove = True

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchUnknown:
	SF_Exception.RaiseFatal(UNKNOWNKEYERROR, &quot;Key&quot;, Key)
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.Remove

REM -----------------------------------------------------------------------------
Public Function RemoveAll() As Boolean
&apos;&apos;&apos;	Remove all the entries from the dictionary
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;	Returns: True if successful
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		myDict.RemoveAll()

Dim vKeys As Variant			&apos;	Array of keys
Dim sColl As String				&apos;	A collection key in MapKeys
Const cstThisSub = &quot;Dictionary.RemoveAll&quot;
Const cstSubArgs = &quot;&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	RemoveAll = False

Check:
	SF_Utils._EnterFunction(cstThisSub, cstSubArgs)

Try:
	vKeys = Keys
	For Each sColl In vKeys
		MapKeys.Remove(sColl)
	Next sColl
	Erase MapKeys
	Erase MapItems
	&apos;	Make dictionary ready to receive new entries
	Call Class_Initialize()
	RemoveAll = True

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.RemoveAll

REM -----------------------------------------------------------------------------
Public Function ReplaceItem(Optional ByVal Key As Variant _
							, Optional ByVal Value As Variant _
							) As Boolean
&apos;&apos;&apos;	Replace the item value
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Key: must exist in the dictionary
&apos;&apos;&apos;	Returns: True if successful
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNKEYERROR: the  old key does not exist
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		myDict.ReplaceItem(&quot;Key&quot;, NewValue)

Dim oItemMap As ItemMap			&apos;	Content to update in the MapItems array
Dim lIndex As Long				&apos;	Entry in the MapItems array
Const cstThisSub = &quot;Dictionary.ReplaceItem&quot;
Const cstSubArgs = &quot;Key, Value&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	ReplaceItem = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(Key, &quot;Key&quot;, V_STRING) Then GoTo Catch
		If IsArray(Value) Then
			If Not SF_Utils._ValidateArray(Value, &quot;Value&quot;) Then GoTo Catch
		Else
			If Not SF_Utils._Validate(Value, &quot;Value&quot;) Then GoTo Catch
		End If
	End If
	If Not Exists(Key) Then GoTo CatchUnknown

Try:
	&apos;	Find entry in MapItems and update it with the new value
	lIndex = MapKeys.Item(Key)
	oItemMap = MapItems(lIndex)
	oItemMap.Value = Value
	ReplaceItem = True

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchUnknown:
	SF_Exception.RaiseFatal(UNKNOWNKEYERROR, &quot;Key&quot;, Key)
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.ReplaceItem

REM -----------------------------------------------------------------------------
Public Function ReplaceKey(Optional ByVal Key As Variant _
							, Optional ByVal Value As Variant _
							) As Boolean
&apos;&apos;&apos;	Replace existing key
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Key: must exist in the dictionary
&apos;&apos;&apos;		Value: must not exist in the dictionary
&apos;&apos;&apos;	Returns: True if successful
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNKEYERROR: the  old key does not exist
&apos;&apos;&apos;		DUPLICATEKEYERROR: the new key exists
&apos;&apos;&apos;	Examples:
&apos;&apos;&apos;		myDict.ReplaceKey(&quot;OldKey&quot;, &quot;NewKey&quot;)

Dim oItemMap As ItemMap			&apos;	Content to update in the MapItems array
Dim lIndex As Long				&apos;	Entry in the MapItems array
Const cstThisSub = &quot;Dictionary.ReplaceKey&quot;
Const cstSubArgs = &quot;Key, Value&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	ReplaceKey = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(Key, &quot;Key&quot;, V_STRING) Then GoTo Catch
		If Not SF_Utils._Validate(Value, &quot;Value&quot;, V_STRING) Then GoTo Catch
	End If
	If Not Exists(Key) Then GoTo CatchUnknown
	If Value = Space(Len(Value)) Then GoTo CatchInvalid
	If Exists(Value) Then GoTo CatchDuplicate

Try:
	&apos;	Remove the Key entry and create a new one in MapKeys
	With MapKeys
		lIndex = .Item(Key)
		.Remove(Key)
		.Add(lIndex, Value)
	End With
	oItemMap = MapItems(lIndex)
	oItemMap.Key = Value
	ReplaceKey = True

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchUnknown:
	SF_Exception.RaiseFatal(UNKNOWNKEYERROR, &quot;Key&quot;, Key)
	GoTo Finally
CatchDuplicate:
	SF_Exception.RaiseFatal(DUPLICATEKEYERROR, &quot;Value&quot;, Value)
	GoTo Finally
CatchInvalid:
	SF_Exception.RaiseFatal(INVALIDKEYERROR, &quot;Key&quot;)
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.ReplaceKey

REM -----------------------------------------------------------------------------
Public Function SetProperty(Optional ByVal PropertyName As Variant _
								, Optional ByRef Value As Variant _
								) As Boolean
&apos;&apos;&apos;	Set a new value to the given property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		PropertyName: the name of the property as a string
&apos;&apos;&apos;		Value: its new value
&apos;&apos;&apos;	Exceptions
&apos;&apos;&apos;		ARGUMENTERROR		The property does not exist

Const cstThisSub = &quot;Dictionary.SetProperty&quot;
Const cstSubArgs = &quot;PropertyName, Value&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	SetProperty = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
	End If

Try:
	Select Case UCase(PropertyName)
		Case Else
	End Select

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary.SetProperty

REM =========================================================== PRIVATE FUNCTIONS

REM -----------------------------------------------------------------------------
Private Function _PropertyGet(Optional ByVal psProperty As String _
								, Optional pvKey As Variant _
								)
&apos;&apos;&apos;	Return the named property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		psProperty: the name of the property
&apos;&apos;&apos;		pvKey: the key to retrieve, numeric or string

Dim vItemMap As Variant			&apos;	Entry in the MapItems array
Dim vArray As Variant			&apos;	To get Keys or Values
Dim i As Long
Dim cstThisSub As String
Dim cstSubArgs As String

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch

	cstThisSub = &quot;SF_Dictionary.get&quot; &amp; psProperty
	If IsMissing(pvKey) Then cstSubArgs = &quot;&quot; Else cstSubArgs = &quot;[Key]&quot;

	SF_Utils._EnterFunction(cstThisSub, cstSubArgs)

	Select Case UCase(psProperty)
		Case UCase(&quot;Count&quot;)
			_PropertyGet = _MapSize - _MapRemoved
		Case UCase(&quot;Item&quot;)
			If Not SF_Utils._Validate(pvKey, &quot;Key&quot;, V_STRING) Then GoTo Catch
			If Exists(pvKey) Then _PropertyGet = MapItems(MapKeys(pvKey)).Value Else _PropertyGet = Empty
		Case UCase(&quot;Keys&quot;), UCase(&quot;Items&quot;)
			vArray = Array()
			If _MapSize - _MapRemoved - 1 &gt;= 0 Then
				ReDim vArray(0 To (_MapSize - _MapRemoved - 1))
				i = -1
				For each vItemMap In MapItems()
					If Not IsEmpty(vItemMap) Then
						i = i + 1
						If UCase(psProperty) = &quot;KEYS&quot; Then vArray(i) = vItemMap.Key Else vArray(i) = vItemMap.Value
					End If
				Next vItemMap
			End If
			_PropertyGet = vArray
	End Select

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_Dictionary._PropertyGet

REM -----------------------------------------------------------------------------
Private Function _Repr() As String
&apos;&apos;&apos;	Convert the Dictionary instance to a readable string, typically for debugging purposes (DebugPrint ...)
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;	Return:
&apos;&apos;&apos;		&quot;[Dictionary] (key1:value1, key2:value2, ...)

Dim sDict As String			&apos;	Return value
Dim vKeys As Variant		&apos;	Array of keys
Dim sKey As String			&apos;	Tempry key
Dim vItem As Variant		&apos;	Tempry item
Const cstDictEmpty = &quot;[Dictionary] ()&quot;
Const cstDict = &quot;[Dictionary]&quot;
Const cstMaxLength = 50	&apos;	Maximum length for items
Const cstSeparator = &quot;, &quot;

	_Repr = &quot;&quot;

	If Count = 0 Then
		sDict = cstDictEmpty
	Else
		sDict = cstDict &amp; &quot; (&quot;
		vKeys = Keys
		For Each sKey in vKeys
			vItem = Item(sKey)
			sDict = sDict &amp; sKey &amp; &quot;:&quot; &amp; SF_Utils._Repr(vItem, cstMaxLength) &amp; cstSeparator
		Next sKey
		sDict = Left(sDict, Len(sDict) - Len(cstSeparator)) &amp; &quot;)&quot;	&apos;	Suppress last comma
	End If

	_Repr = sDict

End Function	&apos;	ScriptForge.SF_Dictionary._Repr

REM ============================================ END OF SCRIPTFORGE.SF_DICTIONARY
</script:module>