summaryrefslogtreecommitdiffstats
path: root/source/text/sbasic/shared/03/sf_dictionary.xhp
blob: 5ac5d795351c07a17b7da390eba5c473ad3bbe42 (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
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
-->

<meta>
  <topic id="SF_Dictionary" indexer="include" status="PUBLISH">
    <title id="tit" xml-lang="en-US">ScriptForge.Dictionary service</title>
    <filename>/text/sbasic/shared/03/sf_dictionary.xhp</filename>
  </topic>
</meta>
<body>
<section id="abstract">
    <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id261582733781987">
      <bookmark_value>Dictionary service</bookmark_value>
      <bookmark_value>API;DateTime</bookmark_value>
      <bookmark_value>API;PropertyValue</bookmark_value>
   </bookmark>

  <h1 id="hd_id731582733781114" xml-lang="en-US"><link href="text/sbasic/shared/03/sf_dictionary.xhp" name="ScriptForge.Dictionary service"><literal>ScriptForge</literal>.<literal>Dictionary</literal> service</link></h1>
  
  <paragraph role="paragraph" id="par_id891582884466217" xml-lang="en-US">A dictionary is a collection of key-item pairs</paragraph>
  <list type="unordered">
    <listitem><paragraph id="par_id861582884516571" role="listitem" xml-lang="en-US">The key is a case-insensitive string</paragraph></listitem>
    <listitem><paragraph id="par_id531582884549542" role="listitem" xml-lang="en-US">Items may be of any type</paragraph></listitem>
  </list>
</section>

  <paragraph role="paragraph" id="par_id891582884593057" xml-lang="en-US">Keys and items can be retrieved, counted, updated, and much more.</paragraph>
  <paragraph role="tip" id="par_id971582884636922" xml-lang="en-US">%PRODUCTNAME Basic <literal>Collection</literal> object does not support the retrieval of the keys.
  <br/>Additionally its items contain only primitive Basic data types such as dates, text, numbers, and the like.</paragraph>

  <h2 id="hd_id581582885621841" xml-lang="en-US">Service invocation</h2>
  <paragraph role="paragraph" id="par_id821610388789467">The following example creates <literal>myDict</literal> as an empty dictionary.</paragraph>
  <bascode>
    <paragraph role="bascode" localize="false" id="bas_id851582897798335">GlobalScope.BasicLibraries.loadLibrary("ScriptForge")</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id371582885621964">Dim myDict As Variant</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id201582885621287">myDict = CreateScriptService("Dictionary")</paragraph>
  </bascode>

  <paragraph role="paragraph" id="par_id71158288562139" xml-lang="en-US">It is recommended to free resources after use:</paragraph>
  <bascode>
     <paragraph role="bascode" localize="false" id="bas_id721582885621540">Set myDict = myDict.Dispose()</paragraph>
  </bascode>

  <h2 id="hd_id351582885195476" xml-lang="en-US">Properties</h2>
    <table id="tab_id971582885195582">
    <tablerow>
        <tablecell>
            <paragraph id="par_id41582885195836" role="tablehead" xml-lang="en-US">Name</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id31582885195372" role="tablehead" xml-lang="en-US">Readonly</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id31582885195238" role="tablehead" xml-lang="en-US">Type</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id931582885195131" role="tablehead" xml-lang="en-US" >Description</paragraph>
        </tablecell>
    </tablerow>
    <tablerow>
        <tablecell>
            <paragraph id="par_id97158288519551" role="tablecontent" localize="false">Count</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id221582885195686" role="tablecontent" xml-lang="en-US">Yes</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id371582885195525" role="tablecontent" localize="false">Long</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id881582885195976" role="tablecontent" xml-lang="en-US">The number of entries in the dictionary</paragraph>
        </tablecell>
    </tablerow>
    <tablerow>
        <tablecell>
            <paragraph id="par_id841582886030384" role="tablecontent" localize="false">Items</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id441582886030118" role="tablecontent" xml-lang="en-US">Yes</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id131582886030297" role="tablecontent" xml-lang="en-US">Array of Variants</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id471582886030489" role="tablecontent" xml-lang="en-US">The list of items as a one dimensional array</paragraph>
        </tablecell>
    </tablerow>
    <tablerow>
        <tablecell>
            <paragraph id="par_id231582886791351" role="tablecontent" localize="false">Keys</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id971582886791838" role="tablecontent" xml-lang="en-US">Yes</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id271582886791111" role="tablecontent" xml-lang="en-US">Array of Strings</paragraph>
        </tablecell>
        <tablecell>
            <paragraph id="par_id16158288679167" role="tablecontent" xml-lang="en-US">The list of keys as a one dimensional array</paragraph>
        </tablecell>
    </tablerow>
    </table>

    <paragraph role="tip" id="par_id461582886731495" xml-lang="en-US">The <literal>Keys</literal> and <literal>Items</literal> properties return their respective contents, using an identical ordering. The order is unrelated to the creation sequence.</paragraph>

    <h3 id="hd_id691582887572811" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
    <paragraph role="paragraph" id="par_id931610389113917">The following example uses the <literal>Keys</literal> property to iterate over all keys in the dictionary <literal>myDict</literal>.</paragraph>
    <bascode>
    <paragraph role="bascode" localize="false" id="bas_id211582887012398">Dim a As Variant, b As String</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id351582887179042">a = myDict.Keys</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id251582887187534">For Each b In a</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id121582887198799">    MsgBox(myDict.Item(b))</paragraph>
    <paragraph role="bascode" localize="false" id="bas_id571606473148931">Next b</paragraph>
    </bascode>

    <table id="tab_id891606472825856">
    <tablerow>
       <tablecell><paragraph id="par_id581606472825856" role="tablehead" localize="false"></paragraph></tablecell>
       <tablecell><paragraph id="par_id921606472825856" role="tablehead">Methods</paragraph></tablecell>
       <tablecell><paragraph id="par_id781606472825856" role="tablehead"  localize="false"></paragraph></tablecell>
    </tablerow>
    <tablerow>
       <tablecell><paragraph id="par_id381606472825856" role="tablecontent">
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#Add" name="Add method">Add</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#ConvertToArray" name="ConvertToArray method">ConvertToArray</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#ConvertToJson" name="ConvertToJson method">ConvertToJson</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#ConvertToPropertyValues" name="ConvertToPropertyValues method">ConvertToPropertyValues</link>
       </paragraph></tablecell>
       <tablecell><paragraph id="par_id451606472825856" role="tablecontent">
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#Exists" name="Exists method">Exists</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#ImportFromJson" name="ImportFromJson method">ImportFromJson</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#ImportFromPropertyValues" name="ImportFromPropertyValues method">ImportFromPropertyValues</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#Item" name="Item method">Item</link>
       </paragraph></tablecell>
       <tablecell><paragraph id="par_id161606472825856" role="tablecontent">
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#Remove" name="Remove method">Remove</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#RemoveAll" name="RemoveAll method">RemoveAll</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#ReplaceItem" name="ReplaceItem method">ReplaceItem</link><br/>
           <link href="text/sbasic/shared/03/sf_dictionary.xhp#ReplaceKey" name="ReplaceKey method">ReplaceKey</link>
       </paragraph></tablecell>
    </tablerow>
    </table>

  <section id="Add">
  <comment> Add -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id781582887670029">
        <bookmark_value>Dictionary service;Add</bookmark_value>
      </bookmark>
      <h2 id="hd_id831582887670029" localize="false">Add</h2>
        <paragraph role="paragraph" id="par_id831582887670029">Adds a new key-item pair into the dictionary. Returns <literal>True</literal> if successful.</paragraph>
        <h3 id="hd_id451582887670029" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id731582887670029">myDict.Add(Key As String, Item As Variant) As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id821582887670030" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
          <paragraph role="paragraph" id="par_id341582887670030"><emph>Key</emph> : String value used to identify the Item. The key is not case-sensitive.</paragraph>
          <paragraph role="paragraph" id="par_id401582887670030"><emph>Item</emph> : Any value, including an array, a Basic object, a UNO object, a dictionary, etc.</paragraph>
        <h3 id="hd_id461582887670030" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id191582887670030">Dim NewValue As Variant</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id391582887670030">myDict.Add("NewKey", NewValue)</paragraph>
       </bascode>
    <warning id="par_id1001610391308765">Every key must be unique in the same dictionary. If the key already exists in the dictionary, a <literal>DUPLICATEKEYERROR</literal> will be raised. Keys that are made of space characters will raise a <literal>INVALIDKEYERROR</literal> error.</warning>
    </section>

    <section id="ConvertToArray">
    <comment> ConvertToArray -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id621582888424103">
        <bookmark_value>Dictionary service;ConvertToArray</bookmark_value>
      </bookmark>
      <h2 id="hd_id211582888424104" localize="false">ConvertToArray</h2>
        <paragraph role="paragraph" id="par_id81582888424104">Stores the contents of the dictionary in a two-columns zero-based array. The keys are stored in the first column and the items are stored in the second column.</paragraph>
        <paragraph role="paragraph" id="par_id341610391565678">If the dictionary is empty, this method will return an empty <literal>Array</literal>.</paragraph>
        <h3 id="hd_id201582888424104" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id251582888424105">myDict.ConvertToArray() As Variant</paragraph>
        </bascode>
      <h3 id="hd_id461582887670031" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
      <bascode>
        <paragraph role="bascode" localize="false" id="bas_id651610391840491">Dim myDict as Variant</paragraph>
        <paragraph role="bascode" localize="false" id="bas_id381610391862148">myDict = CreateScriptService("Dictionary")</paragraph>
        <paragraph role="bascode" localize="false" id="bas_id61610391873262">myDict.Add("a", 1)</paragraph>
        <paragraph role="bascode" localize="false" id="bas_id351610391876967">myDict.Add("b", 2)</paragraph>
        <paragraph role="bascode" localize="false" id="bas_id491610391880959">myDict.Add("c", 3)</paragraph>
        <paragraph role="bascode" localize="false" id="bas_id521610391883264">Dim arr as Variant</paragraph>
        <paragraph role="bascode" localize="false" id="bas_id361610391885584">arr = myDict.ConvertToArray()</paragraph>
        <paragraph role="bascode" localize="false" id="bas_id911610391888240">'(("a", 1), ("b", 2), ("c", 3))</paragraph>
      </bascode>
    </section>
  
    <section id="ConvertToJson">
        <comment> ConvertToJson --------------------------------------------------------------------------------------------------------------------- </comment>
        <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id631601296836318">
            <bookmark_value>Dictionary service;ConvertToJson</bookmark_value>
        </bookmark>
        <h2 id="hd_id851601296836224" localize="false">ConvertToJson</h2>
        <paragraph role="paragraph" id="par_id831601296836981">Converts the contents of a dictionary to <link href="https://en.wikipedia.org/wiki/JSON" name="JSON text">JSON (JavaScript Object Notation)</link> text.</paragraph>
        <h3 id="hd_id261601297024828" xml-lang="en-US">Limitations</h3>
        <paragraph role="paragraph" id="par_id401601297178073" xml-lang="en-US">This method supports the following data types: <literal>String</literal>, <literal>Boolean</literal>, numbers, <literal>Null</literal> and <literal>Empty</literal>. Arrays containing items of those types are also allowed, whatever their dimensions. Dates are converted into strings, however they cannot be used inside Arrays. Other data types are converted to their string representation using the <literal>SF_String.Represent</literal> service.</paragraph>
        <h3 id="hd_id551601296836572" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
            <paragraph role="bascode" localize="false" id="bas_id491601296836271">myDict.ConvertToJson([Indent As Variant]) As String</paragraph>
        </bascode>
        <h3 id="hd_id1001601296836123" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
      <paragraph role="paragraph" id="par_id8816012968362"><emph>Indent</emph> : When <literal>Indent</literal> is a positive number or a text, JSON array elements and object members are pretty-printed with that indentation level. A negative <literal>Indent</literal> value will add new lines with no indentation. <literal>Indent</literal> default value "" selects the most compact representation. Using a positive integer for <literal>Indent</literal> indents that many spaces per level. When <literal>Indent</literal> is a string, such as <literal>Chr(9)</literal> or <literal>Tab(1)</literal>, the Tab character is used to indent each level.</paragraph>
        <h3 id="hd_id19160129683665" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
            <paragraph role="bascode" localize="false" id="bas_id671601298281962">myDict.Add("p0", 12.5)</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id851601298288784">myDict.Add("p1", "a string àé""ê")</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id201601298295976">myDict.Add("p2", DateSerial(2020,9,28))</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id951601298323286">myDict.Add("p3", True)</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id731601298329491">myDict.Add("p4", Array(1,2,3))</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id451601298336500">MsgBox a.ConvertToJson()    </paragraph>
            <paragraph role="bascode" localize="false" id="bas_id511610392557702">'{"p0": 12.5, "p1": "a string \u00e0\u00e9\"\u00ea", "p2": "2020-09-28", "p3": true, "p4": [1, 2, 3]}</paragraph>
        </bascode>
    </section>

    <section id="ConvertToPropertyValues">
        <comment> ConvertToPropertyValues ----------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id991582889470402">
        <bookmark_value>Dictionary service;ConvertToPropertyValues</bookmark_value>
      </bookmark>
      <h2 id="hd_id421582889470909" localize="false">ConvertToPropertyValues</h2>
        <paragraph role="paragraph" id="par_id151582889470596">Store the content of the dictionary in an array of <literal>PropertyValues</literal>.</paragraph>
        <paragraph role="paragraph" id="par_id231610392665049">Each entry in the array is a <literal>com.sun.star.beans.PropertyValue</literal>. The key is stored in <literal>Name</literal>, the item is stored in <literal>Value</literal>.</paragraph>
        <paragraph role="paragraph" id="par_id341610392705367">If one of the items has a type <literal>Date</literal>, it is converted to a <literal>com.sun.star.util.DateTime</literal> structure. If one of the items is an empty array, it is converted to <literal>Null</literal>. The resulting array is empty when the dictionary is empty.</paragraph>
        <h3 id="hd_id841582889470464" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id191582889470444">myDict.ConvertToPropertyValues() As Variant</paragraph>
        </bascode>
        <h3 id="hd_id461582887670032" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id81610393124521">Dim myDict as Variant</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id971610393127816">myDict = CreateScriptService("Dictionary")</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id531610393130289">'Adds some properties to the dictionary</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id711610393132877">myDict.Add("Color", "Blue")</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id681610393135354">myDict.Add("Width", 20)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id571610393137959">'Converts to an Array of PropertyValue objects</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id351610393140357">Dim prop as Variant</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id101610393142717">prop = myDict.ConvertToPropertyValues()</paragraph>
        </bascode>
        <tip id="par_id421610393306916">Many services and methods in the UNO library take in parameters represented using the <literal>PropertyValue</literal> struct, which is part of the LibreOffice API.</tip>
    </section>

    <section id="Exists">
    <comment> Exists -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id81582889812915">
        <bookmark_value>Dictionary service;Exists</bookmark_value>
      </bookmark>
      <h2 id="hd_id461582889812915" localize="false">Exists</h2>
        <paragraph role="paragraph" id="par_id841582889812916">Determines if a key exists in the dictionary.</paragraph>
        <h3 id="hd_id601582889812916" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id311582889812917">myDict.Exists(Key As String) As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id661582889812917" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
          <paragraph role="paragraph" id="par_id971582889812917"><emph>Key</emph> : The key to be looked up in the dictionary.</paragraph>
        <h3 id="hd_id231582889812918" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id741582889812919">Dim myDict as Variant</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id471582889812919">myDict = CreateScriptService("Dictionary")</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id811606485130666">'Adds some properties to the dictionary</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id391610393640781">myDict.Add("Color", "Blue")</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id891610393643755">myDict.Add("Width", 20)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id531610393646186">'(...)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id491610393648822">If Not myDict.Exists("Size") Then</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id681610393651551">   MsgBox "You have to provide a Size value"</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id581610393654335">End If</paragraph>
        </bascode>
    </section>

    <section id="ImportFromJson">
        <comment> ImportFromJson --------------------------------------------------------------------------------------------------------------------- </comment>
        <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id661601391980619">
            <bookmark_value>Dictionary service;ImportFromJson</bookmark_value>
        </bookmark>
        <h2 id="hd_id81601391980848" localize="false">ImportFromJson</h2>
        <paragraph role="paragraph" id="par_id791601391980978">Adds the content of a <link href="https://en.wikipedia.org/wiki/JSON" name="JSON text">JSON (JavaScript Object Notation)</link> string into the current dictionary. Returns <literal>True</literal> if successful.</paragraph>
        <h3 id="hd_id961601392113644" xml-lang="en-US">Limitations</h3>
        <paragraph role="paragraph" id="par_id481601392181131" xml-lang="en-US">The JSON string may contain numbers, text, booleans, null values and arrays containing those types. It must not contain JSON objects namely sub-dictionaries.</paragraph>
        <paragraph role="paragraph" id="par_id511601392205908" xml-lang="en-US">An attempt is made to convert text to date if the item matches one of these patterns: YYYY-MM-DD, HH:MM:SS or YYYY-MM-DD HH:MM:SS.</paragraph>
        <h3 id="hd_id301601391980982" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
            <paragraph role="bascode" localize="false" id="bas_id401601391980113">myDict.ImportFromJson(InputStr As String, [Overwrite As Boolean]) As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id871601391980130" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
        <paragraph role="paragraph" id="par_id69160139198061"><emph>InputStr</emph> : The string to import.</paragraph>
        <paragraph role="paragraph" id="par_id201601391980268"><emph>Overwrite</emph> : When <literal>True</literal>, entries with same name may exist in the dictionary and their values are overwritten. When <literal>False</literal> (default), repeated keys will raise an error. Beware that dictionary keys are not case-sensitive while names are case-sensitive in JSON strings.</paragraph>
        <h3 id="hd_id141601391980338" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
            <paragraph role="bascode" localize="false" id="bas_id411601393205207">Dim s As String</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id891601393212562">s = "{'firstName': 'John','lastName': 'Smith','isAlive': true,'age': 66, 'birth':  '1954-09-28 20:15:00'" _</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id221601393220997">    &amp; ",'address': {'streetAddress': '21 2nd Street','city': 'New York','state': 'NY','postalCode': '10021-3100'}" _</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id931601393226582">    &amp; ",'phoneNumbers': [{'type': 'home','number': '212 555-1234'},{'type': 'office','number': '646 555-4567'}]" _</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id671601393233042">    &amp; ",'children': ['Q','M','G','T'],'spouse': null}"</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id131601393240390">s = Replace(s, "'", """")</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id351601393248554">myDict.ImportFromJson(s, OverWrite := True)</paragraph>
            <paragraph role="bascode" id="bas_id521601393254694">'The (sub)-dictionaries "address" and "phoneNumbers" (0) and (1) are imported as Empty values.</paragraph>
        </bascode>
    </section>

    <section id="ImportFromPropertyValues">
        <comment> ImportFromPropertyValues --------------------------------------------------------------------------------------------------------------------- </comment>
        <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id791588941968651">
            <bookmark_value>Dictionary service;ImportFromPropertyValues</bookmark_value>
        </bookmark>
        <h2 id="hd_id71588941968955" localize="false">ImportFromPropertyValues</h2>
        <paragraph role="paragraph" id="par_id651588941968228">Inserts the contents of an array of <literal>PropertyValue</literal> objects into the current dictionary. <literal>PropertyValue</literal> Names are used as Keys in the dictionary, whereas Values contain the corresponding values. Returns <literal>True</literal> if successful.</paragraph>
        <h3 id="hd_id82158894196854" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
            <paragraph role="bascode" localize="false" id="bas_id961588941968180">myDict.ImportFromPropertyValues(PropertyValues As Variant [, Overwrite As Boolean]) As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id271588941968528" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
        <paragraph role="paragraph" id="par_id751588941968522"><emph>PropertyValues</emph> : A zero-based 1 dimensional array containing <literal>com.sun.star.beans.PropertyValue</literal> objects. This parameter may also be a single <literal>PropertyValue</literal> object not contained in an Array.</paragraph>
        <paragraph role="paragraph" id="par_id21588941968131"><emph>Overwrite</emph> : When <literal>True</literal>, entries with same name may exist in the dictionary and their values are overwritten. When <literal>False</literal> (default), repeated keys will raise an error. Note that dictionary keys are not case-sensitive, whereas names are case-sensitive in sets of property values.</paragraph>
        <h3 id="hd_id501588941968965" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
            <paragraph role="bascode" localize="false" id="bas_id951588941968987">Dim vProp As New com.sun.star.beans.PropertyValue</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id831588943409828">vProp.Name = "prop"</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id891610395011237">vProp.Value = CDateToUnoDateTime(Now)</paragraph>
            <paragraph role="bascode" localize="false" id="bas_id771588941968883">myDict.ImportFromPropertyValues(vProp, Overwrite := True)</paragraph>
        </bascode>
    </section>

    <section id="Item">
    <comment> Item -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id741582980366762">
        <bookmark_value>Dictionary service;Item</bookmark_value>
      </bookmark>
      <h2 id="hd_id301582098366573" localize="false">Item</h2>
        <paragraph role="paragraph" id="par_id891582890366737">Retrieves an existing dictionary entry based on its key. Returns the value of the item if successful, otherwise returns <literal>Empty</literal>.</paragraph>
        <h3 id="hd_id731582900366531" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id71588290366664">myDict.Item(Key As String) As Variant</paragraph>
        </bascode>
        <h3 id="hd_id751782890366698" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
          <paragraph role="paragraph" id="par_id551582890399669"><emph>Key</emph> : Not case-sensitive. Must exist in the dictionary, otherwise a <literal>UNKNOWNKEYERROR</literal> error is raised.</paragraph>
        <h3 id="hd_id81583890366375" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <paragraph role="paragraph" id="par_id181610395933967">The following example iterates over all keys in the dictionary and uses the <literal>Item</literal> method to access their values.</paragraph>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id371528890366702">Dim myDict as Variant, k as Variant, allKeys as Variant</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id661610395517565">myDict = CreateScriptService("Dictionary")</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id181610395523430">myDict.Add("key1", 100)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id621610395527679">myDict.Add("key2", 200)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id871610395530158">myDict.Add("key3", 300)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id891610395534807">allKeys = myDict.Keys</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id71610395537640">For Each k in allKeys</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id411610395540304">   MsgBox(myDict.Item(k))</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id931610395543522">Next k</paragraph>
       </bascode>
    </section>

    <section id="Remove">
    <comment> Remove -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id741582890366762">
        <bookmark_value>Dictionary service;Remove</bookmark_value>
      </bookmark>
      <h2 id="hd_id301582890366573" localize="false">Remove</h2>
        <paragraph role="paragraph" id="par_id891582890388737">Removes an existing dictionary entry based on its key. Returns <literal>True</literal> if successful.</paragraph>
        <h3 id="hd_id731582890366531" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id71582890366664">myDict.Remove(Key As String) As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id771582890366698" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
          <paragraph role="paragraph" id="par_id551582890366999"><emph>Key</emph> : Not case-sensitive. Must exist in the dictionary, otherwise an <literal>UNKNOWNKEYERROR</literal> error is raised.</paragraph>
        <h3 id="hd_id81582890366375" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id56158289627581">myDict.Add("key1", 100)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id651610399290742">myDict.Add("key2", 200)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id741610399296091">myDict.Add("key3", 300)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id591610399299316">MsgBox(myDict.Count) 'Prints "3"</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id661610399302807">myDict.Remove("key2")</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id671610399305808">MsgBox(myDict.Count) 'Prints "2"</paragraph>
       </bascode>
    </section>

    <section id="RemoveAll">
    <comment> RemoveAll -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id471582896275914">
        <bookmark_value>Dictionary service;RemoveAll</bookmark_value>
      </bookmark>
      <h2 id="hd_id911582896275637" localize="false">RemoveAll</h2>
        <paragraph role="paragraph" id="par_id921582896275624">Removes all the entries from the dictionary. Returns <literal>True</literal> if successful.</paragraph>
        <h3 id="hd_id161582896275448" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode"  localize="false" id="bas_id561610400492690">myDict.RemoveAll() As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id81582890366376" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id56158289627580">myDict.Add("key1", 100)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id651610399290743">myDict.Add("key2", 200)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id741610399296092">myDict.Add("key3", 300)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id591610399299317">MsgBox(myDict.Count) 'Prints "3"</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id661610399302808">myDict.RemoveAll()</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id671610399305809">MsgBox(myDict.Count) 'Prints "0"</paragraph>
        </bascode>
    </section>

    <section id="ReplaceItem">
    <comment> ReplaceItem -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id891582895615851">
        <bookmark_value>Dictionary service;ReplaceItem</bookmark_value>
      </bookmark>
      <h2 id="hd_id801582895615477" localize="false">ReplaceItem</h2>
        <paragraph role="paragraph" id="par_id281582895615444">Replaces an existing item value based on its key. Returns <literal>True</literal> if successful.</paragraph>
        <h3 id="hd_id66158289561569" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id51582895615226">myDict.ReplaceItem(Key As String, Value As Variant) As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id521582895615249" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
          <paragraph role="paragraph" id="par_id991582895615535"><emph>Key</emph> : String value representing the key whose value will be replaced. Not case-sensitive. If the key does not exist in the dictionary, a <literal>UNKNOWNKEYERROR</literal> error is raised.</paragraph>
          <paragraph role="paragraph" id="par_id721582895615186"><emph>Value</emph> : The new value of the item referred to with the Key parameter.</paragraph>
        <h3 id="hd_id781582895615372" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id581582895615680">myDict.Add("a", 1)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id351582895615555">MsgBox(myDict.Item("a")) 'Prints "1"</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id361610399892402">myDict.ReplaceItem("a", 100)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id411610399896001">MsgBox(myDict.Item("a")) ' Prints "100"</paragraph>
       </bascode>
    </section>

    <section id="ReplaceKey">
    <comment> ReplaceKey -------------------------------------------------------------------------------------------------------------------------- </comment>
      <bookmark xml-lang="en-US" localize="false" branch="index" id="bm_id411582896597981">
        <bookmark_value>Dictionary service;ReplaceKey</bookmark_value>
      </bookmark>
      <h2 id="hd_id231582896597839" localize="false">ReplaceKey</h2>
        <paragraph role="paragraph" id="par_id571582896597766">Replaces an existing key in the dictionary by a new key. The item value is left unchanged. Returns <literal>True</literal> if successful.</paragraph>
        <h3 id="hd_id441582896597550" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functsyntax"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id351582896597447">myDict.ReplaceKey(Key As String, Value As String) As Boolean</paragraph>
        </bascode>
        <h3 id="hd_id791582896597306" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functparameters"/></h3>
          <paragraph role="paragraph" id="par_id911582896597619"><emph>Key</emph> : String value representing the key to be replaced. Not case-sensitive. If the key does not exist in the dictionary, a <literal>UNKNOWNKEYERROR</literal> error is raised.</paragraph>
          <paragraph role="paragraph" id="par_id531582896597989"><emph>Value</emph> : String value for the new key. Not case-sensitive. If the new key already exists in the dictionary, a <literal>DUPLICATEKEYERROR</literal> error is raised.</paragraph>
        <h3 id="hd_id931582896597782" localize="false"><embedvar href="text/sbasic/shared/00000003.xhp#functexample"/></h3>
        <bascode>
          <paragraph role="bascode" localize="false" id="bas_id521582896597313">myDict.Add("oldKey", 100)</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id961610400326541">MsgBox(myDict.Item("oldKey")) 'Prints "100"</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id631610400329115">myDict.ReplaceKey("oldKey", "newKey")</paragraph>
          <paragraph role="bascode" localize="false" id="bas_id761610400331545">MsgBox(myDict.Item("newKey")) ' Prints "100"</paragraph>
       </bascode>
    </section>

    <embed href="text/sbasic/shared/03/lib_ScriptForge.xhp#SF_InternalUse"/>

</body>
</helpdocument>