<!DOCTYPE html>
<html lang="es" dir="ltr">
<head>
<base href="../../../../../">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Servicio ScriptForge.Dictionary</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="es/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="es/bookmarks.js" defer></script><script type="text/javascript" src="es/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="es/text/shared/05/new_help.html"><div></div></a><a class="logo" href="es/text/shared/05/new_help.html"><p dir="auto">Ayuda de LibreOffice 25.2</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Módulo</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contenido</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Buscar en los marcadores del módulo elegido" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
<noscript><div id="WarnJS"><h1 dir="auto">Active JavaScript en el navegador para mostrar las páginas de ayuda de LibreOffice.</h1></div></noscript>
<a id="abstract"></a>
<a id="bm_id261582733781987"></a>
<meta itemprop="keywords" content="Dictionary service">
<h1 id="hd_id731582733781114" dir="auto">
<a id="SFDictionary"></a><span class="literal">ScriptForge</span>.<span class="literal">Dictionary</span> service</h1>
<p id="par_id891582884466217" class="paragraph" dir="auto">A dictionary is a collection of key-item pairs</p>
<ul itemprop="Unordered" itemscope="true" itemtype="http://schema.org/ItemList" dir="auto">
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto"><p id="par_id861582884516571" class="listitem" dir="auto">The key is a case-insensitive string</p></li>
<li itemprop="itemListElement" itemscope="true" itemtype="http://schema.org/ItemListUnordered" dir="auto"><p id="par_id531582884549542" class="listitem" dir="auto">Items may be of any type</p></li>
</ul>
<p id="par_id891582884593057" class="paragraph" dir="auto">Keys and items can be retrieved, counted, updated, and much more.</p>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="Icono de consejo" style="width:40px;height:40px;"></div>
<div class="notetext"><p dir="auto">The Dictionary service is similar to the built-in LibreOffice Basic <span class="literal">Collection</span> object, however with more features. For example, <span class="literal">Collection</span> objects do not support the retrieval of keys. Moreover, Dictionaries provide additional capabilities as replacing keys, testing if a specific key already exists and converting the Dictionary into an Array object or JSON string.</p></div>
</div>
<br>
<h2 id="hd_id581582885621841" dir="auto">Invocación del servicio</h2>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<p id="par_id821610388789467" class="paragraph" dir="auto">The following example creates <span class="literal">myDict</span> as an empty dictionary.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
Dim myDict As Variant
myDict = CreateScriptService("Dictionary")
</code></pre></div>
<p id="par_id71158288562139" class="paragraph" dir="auto">Es recomendable liberar recursos después del uso:</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Set myDict = myDict.Dispose()
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<p id="par_id551626869252987" class="paragraph" dir="auto">The example below creates an empty instance of the <span class="literal">Dictionary</span> service and uses the Python native <span class="literal">update</span> method to populate it with the contents of a Python <span class="literal">dict</span> object.</p>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
dico = dict('A' = 1, 'B' = 2, 'C' = 3)
# Initialize myDict as an empty dict object
myDict = CreateScriptService('Dictionary')
# Load the values of dico into myDict
myDict.update(dico)
myDict['D'] = 4
print(myDict) # {'A': 1, 'B': 2, 'C': 3, 'D': 4}
propval = myDict.ConvertToPropertyValues()
</code></pre></div>
<p id="par_id981626869718081" class="paragraph" dir="auto">It is possible to create an instance of the <span class="literal">Dictionary</span> service using a Python <span class="literal">dict</span> object as argument as shown in the following example.</p>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
dico = dict('A' = 1, 'B' = 2, 'C' = 3)
# Inicializa myDict con el contenido de dico
myDict = CreateScriptService('Dictionary', dico)
myDict['D'] = 4
print(myDict) # {'A': 1, 'B': 2, 'C': 3, 'D': 4}
propval = myDict.ConvertToPropertyValues()
</code></pre></div>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id211626699007613" dir="auto">Because Python has built-in dictionary support, most of the methods in the <span class="literal">Dictionary</span> service are available for Basic scripts only. Exceptions are <span class="literal">ConvertToPropertyValues</span> and <span class="literal">ImportFromPropertyValues</span> that are supported in both Basic and Python.</p></div>
</div>
<br>
<h2 id="hd_id351582885195476" dir="auto">Propiedades</h2>
<a id="properties_toc"></a>
<table border="1" class="" cellpadding="0" cellspacing="0">
<tr>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id41582885195836" class="tableheadintable" dir="auto">Nombre</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id31582885195372" class="tableheadintable" dir="auto">Solo lectura</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id31582885195238" class="tableheadintable" dir="auto">Tipo</p>
</th>
<th rowspan="" colspan="" class="tableheadcell" dir="auto">
<p id="par_id931582885195131" class="tableheadintable" dir="auto">Descripción</p>
</th>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id97158288519551" class="tablecontentintable" dir="auto">Count</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id221582885195686" class="tablecontentintable" dir="auto">Sí</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id371582885195525" class="tablecontentintable" dir="auto">Long</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id881582885195976" class="tablecontentintable" dir="auto">El número de entradas en el diccionario</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id841582886030384" class="tablecontentintable" dir="auto">Items</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id441582886030118" class="tablecontentintable" dir="auto">Sí</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id131582886030297" class="tablecontentintable" dir="auto">Matriz de variantes</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id471582886030489" class="tablecontentintable" dir="auto">La lista de elementos como una matriz unidimensional</p>
</td>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id231582886791351" class="tablecontentintable" dir="auto">Keys</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id971582886791838" class="tablecontentintable" dir="auto">Sí</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id271582886791111" class="tablecontentintable" dir="auto">Matriz de cadenas</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id16158288679167" class="tablecontentintable" dir="auto">The list of keys as a one dimensional array</p>
</td>
</tr>
</table>
<br>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="Icono de consejo" style="width:40px;height:40px;"></div>
<div class="notetext"><p dir="auto">The <span class="literal">Keys</span> and <span class="literal">Items</span> properties return their respective contents, using an identical ordering. The order is unrelated to the creation sequence.</p></div>
</div>
<br>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<p id="par_id931610389113917" class="paragraph" dir="auto">The following example uses the <span class="literal">Keys</span> property to iterate over all keys in the dictionary <span class="literal">myDict</span>.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim a As Variant, b As String
a = myDict.Keys
For Each b In a
MsgBox(myDict.Item(b))
Next b
</code></pre></div>
<a id="methods_toc"></a>
<table border="1" class="" cellpadding="0" cellspacing="0">
<tr>
<th rowspan="" colspan="3" class="tableheadcell" dir="auto">
<p id="par_id891611613601554" class="tableheadintable" dir="auto">Lista de métodos en el servicio Dictionary</p>
</th>
</tr>
<tr>
<td rowspan="" colspan="" dir="auto">
<p id="par_id381606472825856" class="tablecontentintable" dir="auto">
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#Add">Add</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#ConvertToArray">ConvertToArray</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#ConvertToJson">ConvertToJson</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#ConvertToPropertyValues">ConvertToPropertyValues</a>
</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id451606472825856" class="tablecontentintable" dir="auto">
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#Exists">Exists</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#ImportFromJson">ImportFromJson</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#ImportFromPropertyValues">ImportFromPropertyValues</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#Item">Item</a>
</p>
</td>
<td rowspan="" colspan="" dir="auto">
<p id="par_id161606472825856" class="tablecontentintable" dir="auto">
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#Remove">Remove</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#RemoveAll">RemoveAll</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#ReplaceItem">ReplaceItem</a><br>
<a target="_top" href="es/text/sbasic/shared/03/sf_dictionary.html#ReplaceKey">ReplaceKey</a>
</p>
</td>
</tr>
</table>
<br>
<a id="Add"></a>
<a id="bm_id781582887670029"></a>
<meta itemprop="keywords" content="Dictionary service,Add">
<h2 id="hd_id831582887670029" dir="auto">Add</h2>
<p id="par_id831582887670029" class="paragraph" dir="auto">Adds a new key-item pair into the dictionary. Returns <span class="literal">True</span> if successful.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id881626699610355" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.Add(key: str, item: any): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id341582887670030" class="paragraph" dir="auto"><span class="emph">key</span>: String value used to identify the Item. The key is not case-sensitive.</p>
<p id="par_id401582887670030" class="paragraph" dir="auto"><span class="emph">item</span>: Any value, including an array, a Basic object, a UNO object, a dictionary, etc.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim NewValue As Variant
myDict.Add("NewKey", NewValue)
</code></pre></div>
<div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id1001610391308765" dir="auto">Every key must be unique in the same dictionary. If the key already exists in the dictionary, a <span class="literal">DUPLICATEKEYERROR</span> will be raised. Keys that are made of space characters will raise a <span class="literal">INVALIDKEYERROR</span> error.</p></div>
</div>
<br>
<a id="ConvertToArray"></a>
<a id="bm_id621582888424103"></a>
<meta itemprop="keywords" content="Dictionary service,ConvertToArray">
<h2 id="hd_id211582888424104" dir="auto">ConvertToArray</h2>
<p id="par_id81582888424104" class="paragraph" dir="auto">Almacena el contenido del diccionario en una matriz bicolumnar con índice inicial cero. Las claves se almacenan en la primera columna y los elementos, en la segunda.</p>
<p id="par_id341610391565678" class="paragraph" dir="auto">If the dictionary is empty, this method will return an empty <span class="literal">Array</span>.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id71626699963594" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.ConvertToArray(): any[0..*, 0..1]</span>
</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim myDict as Variant
myDict = CreateScriptService("Dictionary")
myDict.Add("a", 1)
myDict.Add("b", 2)
myDict.Add("c", 3)
Dim arr as Variant
arr = myDict.ConvertToArray()
'(("a", 1), ("b", 2), ("c", 3))
</code></pre></div>
<a id="ConvertToJson"></a>
<a id="bm_id631601296836318"></a>
<meta itemprop="keywords" content="Dictionary service,ConvertToJson">
<h2 id="hd_id851601296836224" dir="auto">ConvertToJson</h2>
<p id="par_id831601296836981" class="paragraph" dir="auto">Converts the contents of a dictionary to <a target="_blank" href="https://en.wikipedia.org/wiki/JSON">JSON (JavaScript Object Notation)</a> text.</p>
<h3 id="hd_id261601297024828" dir="auto">Limitaciones</h3>
<p id="par_id401601297178073" class="paragraph" dir="auto">This method supports the following data types: <span class="literal">String</span>, <span class="literal">Boolean</span>, numbers, <span class="literal">Null</span> and <span class="literal">Empty</span>. 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 <span class="literal">SF_String.Represent</span> service.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id901626700139467" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.ConvertToJson(indent: str = ""): str</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id8816012968362" class="paragraph" dir="auto"><span class="emph">indent</span>: When <span class="literal">indent</span> is a positive number or a text, JSON array elements and object members are pretty-printed with that indentation level. A negative <span class="literal">indent</span> value will add new lines with no indentation. The default value is an empty string "" which selects the most compact representation. Using a positive integer for <span class="literal">indent</span> indents that many spaces per level. When <span class="literal">indent</span> is a string, such as <span class="literal">Chr(9)</span> or <span class="literal">Tab(1)</span>, the Tab character is used to indent each level.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDict.Add("p0", 12.5)
myDict.Add("p1", "a string àé""ê")
myDict.Add("p2", DateSerial(2020,9,28))
myDict.Add("p3", True)
myDict.Add("p4", Array(1,2,3))
MsgBox myDict.ConvertToJson()
'{"p0": 12.5, "p1": "a string \u00e0\u00e9\"\u00ea", "p2": "2020-09-28", "p3": true, "p4": [1, 2, 3]}
</code></pre></div>
<a id="ConvertToPropertyValues"></a>
<a id="bm_id991582889470402"></a>
<meta itemprop="keywords" content="Dictionary service,ConvertToPropertyValues">
<meta itemprop="keywords" content="API,PropertyValue">
<meta itemprop="keywords" content="API,DateTime">
<h2 id="hd_id421582889470909" dir="auto">ConvertToPropertyValues</h2>
<p id="par_id151582889470596" class="paragraph" dir="auto">Stores the contents of the dictionary into an array of <span class="literal">PropertyValues</span>.</p>
<p id="par_id231610392665049" class="paragraph" dir="auto">Each entry in the array is a <span class="literal">com.sun.star.beans.PropertyValue</span>. The key is stored in <span class="literal">Name</span>, the item is stored in <span class="literal">Value</span>.</p>
<p id="par_id341610392705367" class="paragraph" dir="auto">If one of the items has a type <span class="literal">Date</span>, it is converted to a <span class="literal">com.sun.star.util.DateTime</span> structure. If one of the items is an empty array, it is converted to <span class="literal">Null</span>. The resulting array is empty when the dictionary is empty.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id481626700464253" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.ConvertToPropertyValues(): obj[0..*]</span>
</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim myDict as Variant
myDict = CreateScriptService("Dictionary")
'Añade determinadas propiedades al diccionario
myDict.Add("Color", "Blue")
myDict.Add("Width", 20)
'Lo convierte en una matriz de objetos PropertyValue
Dim prop as Variant
prop = myDict.ConvertToPropertyValues()
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<p id="par_id771626700938786" class="paragraph" dir="auto">Note in the example below that a Python dictionary needs to be passed as the second argument of the <span class="literal">CreateScriptService</span> method.</p>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
myDict = dict()
myDict["Color"] = "Blue"
myDict["Width"] = 30
sfDic = CreateScriptService("Dictionary", myDict)
prop = sfDic.ConvertToPropertyValues()
</code></pre></div>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id421610393306916" dir="auto">Many services and methods in the UNO library take in parameters represented using the <span class="literal">PropertyValue</span> struct, which is part of the LibreOffice API.</p></div>
</div>
<br>
<a id="Exists"></a>
<a id="bm_id81582889812915"></a>
<meta itemprop="keywords" content="Dictionary service,Exists">
<h2 id="hd_id461582889812915" dir="auto">Exists</h2>
<p id="par_id841582889812916" class="paragraph" dir="auto">Determina si existe una clave en el diccionario.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id441626701103153" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.Exists(key: str): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id971582889812917" class="paragraph" dir="auto"><span class="emph">key</span>: The key to be looked up in the dictionary.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim myDict as Variant
myDict = CreateScriptService("Dictionary")
'Añade determinadas propiedades al diccionario
myDict.Add("Color", "Blue")
myDict.Add("Width", 20)
'(...)
If Not myDict.Exists("Size") Then
MsgBox "You have to provide a Size value"
End If
</code></pre></div>
<a id="ImportFromJson"></a>
<a id="bm_id661601391980619"></a>
<meta itemprop="keywords" content="Dictionary service,ImportFromJson">
<h2 id="hd_id81601391980848" dir="auto">ImportFromJson</h2>
<p id="par_id791601391980978" class="paragraph" dir="auto">Adds the content of a <a target="_blank" href="https://en.wikipedia.org/wiki/JSON">JSON (JavaScript Object Notation)</a> string into the current dictionary. Returns <span class="literal">True</span> if successful.</p>
<h3 id="hd_id961601392113644" dir="auto">Limitaciones</h3>
<p id="par_id481601392181131" class="paragraph" dir="auto">La cadena JSON puede contener números, texto, valores booleanos, valores nulos y matrices que contengan esos tipos. No debe contener objetos JSON; en concreto, subdiccionarios.</p>
<p id="par_id511601392205908" class="paragraph" dir="auto">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.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id841626701235169" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.ImportFromJson(inputstr: str, overwrite: bool = False): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id69160139198061" class="paragraph" dir="auto"><span class="emph">inputstr</span>: la cadena que se importará.</p>
<p id="par_id201601391980268" class="paragraph" dir="auto"><span class="emph">overwrite</span>: When <span class="literal">True</span>, entries with same name may exist in the dictionary and their values are overwritten. When <span class="literal">False</span> (default), repeated keys will raise an error. Be aware that dictionary keys are not case-sensitive while names are case-sensitive in JSON strings.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim s As String
s = "{'firstName': 'John','lastName': 'Smith','isAlive': true,'age': 66, 'birth': '1954-09-28 20:15:00'" _
& ",'address': {'streetAddress': '21 2nd Street','city': 'New York','state': 'NY','postalCode': '10021-3100'}" _
& ",'phoneNumbers': [{'type': 'home','number': '212 555-1234'},{'type': 'office','number': '646 555-4567'}]" _
& ",'children': ['Q','M','G','T'],'spouse': null}"
s = Replace(s, "'", """")
myDict.ImportFromJson(s, OverWrite := True)
'The (sub)-dictionaries "address" and "phoneNumbers" (0) and (1) are imported as Empty values.
</code></pre></div>
<a id="ImportFromPropertyValues"></a>
<a id="bm_id791588941968651"></a>
<meta itemprop="keywords" content="Dictionary service,ImportFromPropertyValues">
<h2 id="hd_id71588941968955" dir="auto">ImportFromPropertyValues</h2>
<p id="par_id651588941968228" class="paragraph" dir="auto">Inserts the contents of an array of <span class="literal">PropertyValue</span> objects into the current dictionary. <span class="literal">PropertyValue</span> Names are used as Keys in the dictionary, whereas Values contain the corresponding values. Returns <span class="literal">True</span> if successful.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id431626701465848" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.ImportFromPropertyValues(propertyvalues: obj[0..*], overwrite: bool = False): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id751588941968522" class="paragraph" dir="auto"><span class="emph">propertyvalues</span>: A zero-based 1-dimensional array containing <span class="literal">com.sun.star.beans.PropertyValue</span> objects. This parameter may also be a single <span class="literal">PropertyValue</span> object not contained in an Array.</p>
<p id="par_id21588941968131" class="paragraph" dir="auto"><span class="emph">overwrite</span>: When <span class="literal">True</span>, entries with same name may exist in the dictionary and their values are overwritten. When <span class="literal">False</span> (default), repeated keys will raise an error. Note that dictionary keys are not case-sensitive in Basic, whereas names are case-sensitive in sets of property values and in Python dictionaries.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<p id="par_id641626703615898" class="paragraph" dir="auto">Los ejemplos siguientes crean en primer lugar una matriz con dos objetos <span class="literal">PropertyValue</span> y luego la convierten en un diccionario.</p>
<div class="embedded">
<a id="In_Basic"></a>
<h5 id="hd_id191620312698501" dir="auto">En BASIC</h5>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim vProp As New com.sun.star.beans.PropertyValue
Dim arrProp : arrProp = Array()
vProp.Name = "Color"
vProp.Value = "Blue"
arrProp = SF_Array.Append(arrProp, vProp)
vProp.Name = "Date"
vProp.Value = CDateToUnoDateTime(Now)
arrProp = SF_Array.Append(arrProp, vProp)
myDict = CreateScriptService("Dictionary")
myDict.ImportFromPropertyValues(arrProp, Overwrite := True)
Dim keys : keys = myDict.Keys
For Each k In keys
MsgBox k & " - " & myDict.Item(k)
Next k
</code></pre></div>
<div class="embedded">
<a id="In_Python"></a>
<h5 id="hd_id831620312769993" dir="auto">En Python</h5>
</div>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-python line-numbers">
from scriptforge import CreateScriptService
from datetime import datetime
import uno
bas = CreateScriptService("Basic")
arrProp = list()
vProp = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
vProp.Name = "Color"
vProp.Value = "Blue"
arrProp.append(vProp)
vProp = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
vProp.Name = "Date"
vProp.Value = bas.CDateToUnoDateTime(datetime.now())
arrProp.append(vProp)
myDict = CreateScriptService("Dictionary")
myDict.ImportFromPropertyValues(arrProp, overwrite=True)
for k in myDict.keys():
bas.MsgBox("{} - {}".format(k, myDict[k]))
</code></pre></div>
<a id="Item"></a>
<a id="bm_id741582980366762"></a>
<meta itemprop="keywords" content="Dictionary service,Item">
<h2 id="hd_id301582098366573" dir="auto">Item</h2>
<p id="par_id891582890366737" class="paragraph" dir="auto">Retrieves an existing dictionary entry based on its key. Returns the value of the item if successful, otherwise returns <span class="literal">Empty</span>.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id501626704949678" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.Item(key: str): any</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id551582890399669" class="paragraph" dir="auto"><span class="emph">key</span>: Not case-sensitive. If it does not exist, <span class="literal">Empty</span> value is returned.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<p id="par_id181610395933967" class="paragraph" dir="auto">The following example iterates over all keys in the dictionary and uses the <span class="literal">Item</span> method to access their values.</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
Dim myDict as Variant, k as Variant, allKeys as Variant
myDict = CreateScriptService("Dictionary")
myDict.Add("key1", 100)
myDict.Add("key2", 200)
myDict.Add("key3", 300)
allKeys = myDict.Keys
For Each k in allKeys
MsgBox(myDict.Item(k))
Next k
</code></pre></div>
<a id="Remove"></a>
<a id="bm_id741582890366762"></a>
<meta itemprop="keywords" content="Dictionary service,Remove">
<h2 id="hd_id301582890366573" dir="auto">Remove</h2>
<p id="par_id891582890388737" class="paragraph" dir="auto">Removes an existing dictionary entry based on its key. Returns <span class="literal">True</span> if successful.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id861626705083007" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.Remove(key: str): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id551582890366999" class="paragraph" dir="auto"><span class="emph">key</span>: Not case-sensitive. Must exist in the dictionary, otherwise an <span class="literal">UNKNOWNKEYERROR</span> error is raised.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDict.Add("key1", 100)
myDict.Add("key2", 200)
myDict.Add("key3", 300)
MsgBox(myDict.Count) ' 3
myDict.Remove("key2")
MsgBox(myDict.Count) ' 2
</code></pre></div>
<a id="RemoveAll"></a>
<a id="bm_id471582896275914"></a>
<meta itemprop="keywords" content="Dictionary service,RemoveAll">
<h2 id="hd_id911582896275637" dir="auto">RemoveAll</h2>
<p id="par_id921582896275624" class="paragraph" dir="auto">Removes all the entries from the dictionary. Returns <span class="literal">True</span> if successful.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id561626705190520" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.RemoveAll(): bool</span>
</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDict.Add("key1", 100)
myDict.Add("key2", 200)
myDict.Add("key3", 300)
MsgBox(myDict.Count) ' 3
myDict.RemoveAll()
MsgBox(myDict.Count) ' 0
</code></pre></div>
<a id="ReplaceItem"></a>
<a id="bm_id891582895615851"></a>
<meta itemprop="keywords" content="Dictionary service,ReplaceItem">
<h2 id="hd_id801582895615477" dir="auto">ReplaceItem</h2>
<p id="par_id281582895615444" class="paragraph" dir="auto">Replaces an existing item value based on its key. Returns <span class="literal">True</span> if successful.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id551626705258936" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.ReplaceItem(key: str, value: any): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id991582895615535" class="paragraph" dir="auto"><span class="emph">key</span>: String value representing the key whose value will be replaced. Not case-sensitive. If the key does not exist in the dictionary, an <span class="literal">UNKNOWNKEYERROR</span> error is raised.</p>
<p id="par_id721582895615186" class="paragraph" dir="auto"><span class="emph">value</span>: The new value of the item referred to with the <span class="literal">key</span> parameter.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDict.Add("a", 1)
MsgBox(myDict.Item("a")) ' 1
myDict.ReplaceItem("a", 100)
MsgBox(myDict.Item("a")) ' 100
</code></pre></div>
<a id="ReplaceKey"></a>
<a id="bm_id411582896597981"></a>
<meta itemprop="keywords" content="Dictionary service,ReplaceKey">
<h2 id="hd_id231582896597839" dir="auto">ReplaceKey</h2>
<p id="par_id571582896597766" class="paragraph" dir="auto">Replaces an existing key in the dictionary by a new key. The item value is left unchanged. Returns <span class="literal">True</span> if successful.</p>
<div class="embedded">
<a id="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Sintaxis:</h3>
</div>
<p id="par_id851626705393127" class="paragraph" dir="auto">
<span class="input" data-tooltip="Pulse en el texto para copiarlo en el portapapeles">dict.ReplaceKey(key: str, value: str): bool</span>
</p>
<div class="embedded">
<a id="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parámetros:</h3>
</div>
<p id="par_id911582896597619" class="paragraph" dir="auto"><span class="emph">key</span>: String value representing the key to be replaced. Not case-sensitive. If the key does not exist in the dictionary, a <span class="literal">UNKNOWNKEYERROR</span> error is raised.</p>
<p id="par_id531582896597989" class="paragraph" dir="auto"><span class="emph">value</span>: String value for the new key. Not case-sensitive. If the new key already exists in the dictionary, an <span class="literal">DUPLICATEKEYERROR</span> error is raised.</p>
<div class="embedded">
<a id="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Ejemplo:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Pulse en el texto para copiarlo en el portapapeles"><pre dir="auto"><code class="language-visual-basic line-numbers">
myDict.Add("oldKey", 100)
MsgBox(myDict.Item("oldKey")) ' 100
myDict.ReplaceKey("oldKey", "newKey")
MsgBox(myDict.Item("newKey")) ' 100
</code></pre></div>
<div class="embedded">
<a id="SF_InternalUse"></a>
<div class="warning">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/warning.svg" alt="warning" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="par_id851506659675843" dir="auto">Todas las rutinas o identificadores BASIC de <span class="literal">ScriptForge</span> precedidas por guion bajo «_» están reservadas para uso interno. No deben utilizarse en macros BASIC o secuencias Python.</p></div>
</div>
<br>
</div>
<a id="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a id="related"></a><span class="emph">Temas relacionados</span></p>
<div class="relatedbody" itemprop="mentions">
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="es/text/sbasic/shared/03/sf_array.html">Servicio <span class="literal">ScriptForge</span>.<span class="literal">Array</span></a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="es/text/sbasic/shared/collection.html">Objeto Collection</a></p></div>
</div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><h2 style="text-align: center;"><a href="https://books.libreoffice.org" target="_blank">Libros de LibreOffice</a></h2>
<div class="noteicon" dir="auto" style="display:flex;justify-content:center;flex-wrap:wrap;row-gap:15px;">
<img src="media/navigation/libo-writer.svg" alt="Writer Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-calc.svg" alt="Calc Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-impress.svg" alt="Impress Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-draw.svg" alt="Draw Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-base.svg" alt="Base Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-math.svg" alt="Math Icon" style="width:60px;height:60px;"><img src="media/navigation/libo-symbol-black.svg" alt="Getting Started Icon" style="width:60px;height:60px;">
</div>
<div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/shared/03/sf_dictionary.xhp" target="_blank">/text/sbasic/shared/03/sf_dictionary.xhp</a></p>
<p dir="auto">Title is: Servicio ScriptForge.Dictionary</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>