# Working with Variables

You can think of a variable as a box that has a name, type, and value. The name of the variable always starts with the $ sign. In the image below, the first variable is called Result, its value is 1542, and its data type is a number. If a specific data type is specified when creating a variable, it will work with that type. The Result variable, accordingly, can only store numbers.

![](https://sherparpa.ru/wp-content/uploads/2024/02/peremennye.png)

The name of the variable is its unique identifier, and it defines how it is displayed and used.

In Sherpa RPA, there is a special Variables panel where the user can create, rename, and delete variables.

## **Declaring a Variable**

To use a variable, you first need to create it, or, using programming terminology, declare the variable. To do this, you need to enter the $ symbol followed by the name you want to give your variable. The variable name can be anything, but it should not contain spaces or special characters.

![](https://sherparpa.ru/wp-content/uploads/2024/02/2024-02-19_16-58-21.png)

However, it is preferable for it to be descriptive and intuitively clear what data this variable contains. Do not use just single letters, numbers, or long phrases.

Variables can have names in both Russian and English, but the name cannot contain spaces. You can choose the data type for the variable (number, text, expression, etc.). Some types are simple (number, boolean, text type), while others are composite (dictionary, list, data table). You can also set initial values for variables (the value that the variable will take at the moment the script is run).

In many Block Properties, variable names are already specified by default (for example, the variable $ProcessID in the picture). You can use them in your projects, modify them, or enter your own variables.

## **Types of Variables**

The Designer supports a wide variety of data types that can be stored in a variable:

<table data-header-hidden><thead><tr><th width="173"></th><th></th></tr></thead><tbody><tr><td><strong>Variable</strong></td><td><strong>Description</strong></td></tr><tr><td>Text</td><td>Stores text strings. When setting constant values for text variables, these values are always enclosed in quotes.</td></tr><tr><td>Number</td><td>Numbers can be either integers or floating-point. They are written without quotes.</td></tr><tr><td>DataTable</td><td>A data table. Allows you to load necessary values from a selected file and save the entered values to a separate .json file.</td></tr><tr><td>List</td><td>Can store a certain number of strings. You can retrieve the value of a specific string by its index.</td></tr><tr><td>DateTime</td><td>Stores only the date or date and time.</td></tr><tr><td>Dictionary</td><td>A list where each string represents a name and its assigned value (key name and key value).</td></tr><tr><td>HashTable</td><td>A table with “Key” and “Value” columns that can be filled manually. The window also allows you to load necessary key-value pairs from a selected file and save the entered key-value pairs to a separate .json file.</td></tr><tr><td>Logical</td><td>Takes two values (stores one of two constants) – true and false.</td></tr><tr><td>Money</td><td>Contains a numeric value.</td></tr><tr><td>SecureString</td><td>Stores confidential information that must remain confidential.</td></tr><tr><td>Object</td><td>Contains not the actual data values, but a pointer to them.</td></tr></tbody></table>

When creating a variable on the "Variables" panel, its initial value can be set in a special window. The editing interface for some variable types differs; for example, the editing window for a "Hashtable" type variable contains two columns: "Key" and "Value".

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfo-_gDln7XECmBiSXhZgOjPguTbG_CCfyEnrqojg4J0R3OPxyJWwfVxd7Rt5IknKATRQHdSK6WFY6l5s6hUsll009MyjqaE0j3k5GxabvfeE1BCkg-6VDvkhEbBMSbz2_T6UQaC9auGpz3qZvwMy6OqIqd?key=540i16yY7iCYriDxUR-qlA" alt=""><figcaption></figcaption></figure>

The editing interface for a "List" type variable contains a list of values.

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfQzmPFbnBVlpg-6hGVQli1ha-fztVvkUsZUHSL-A0e4w0nsgB8EKdM198tSKOLVQQl7-Iq6loU9FIxXMAs_5TA4W-R-VUkSiRjCuzJBAH_cHl4bBIPdO4OK01_Ds1yNhq5BnP8qU8YGmaTyB5Z2JgxL0BD?key=540i16yY7iCYriDxUR-qlA" alt=""><figcaption></figcaption></figure>

When working with text data types or text constant values, constants are always enclosed in quotes. If you select a variable in the properties and want to assign it a text value, it must be enclosed in quotes:

![](https://sherparpa.ru/wp-content/uploads/2024/02/2024-02-19_17-16-49.png)

If a numeric value is assigned to a variable, it is specified without quotes.

When selecting a composite data type for a variable, you have the option to immediately set the structure of that data type. For example, in the editing window for a "DataTable" type variable, you can specify the number of rows and columns, their headers, and assign them values.

<table data-header-hidden><thead><tr><th width="100"></th><th width="198"></th><th></th></tr></thead><tbody><tr><td><strong>No.</strong></td><td><strong>Interface Element</strong></td><td><strong>Description</strong></td></tr><tr><td>1.</td><td>button<img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeE5Q-UxnD-gol_H5iIGtK5M9aRe4SmEHJYlqbMAibZQShmTIWAgueXnnyJZ5IlscPxmhY9KHzl2JIiSB3S_zwZ6MhIcIEVHAd4s3TG-bR01NCno6KAfntxWqsLjkmQSc2SjS5QKSBcu7o2QYPlCxlF_bw?key=540i16yY7iCYriDxUR-qlA" alt=""></td><td>Allows you to add a column to the data table. When the button is pressed, a window opens for entering the column name.</td></tr><tr><td>2.</td><td>button<img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdzdGP2bOcy-BzTIyaJtRzSVxM7SORVMa33TUMXtB-Oyar_0nmpkfaYtPfufMt45bD2AoQiY6JXrG7LcpviPPB9YheqwLztmIOhXl-2nHSlYKCwmWMqlDsryTGNoVY3ootT6sofgDjs3iq-RTZdPzDcPc7q?key=540i16yY7iCYriDxUR-qlA" alt=""></td><td>Allows you to add a new row to the data table.</td></tr><tr><td>3.</td><td>button <img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfoFAmNVZcZS6ZlxsIbeatCWeT6NJsdEPtIx0fPUcrpOeeWFH9SnNdo9wQa0OZ0iXwGZEekpAv8UX6Z27FCdaWDapZ9Js_TMZSeJJLdY3K2VqzTNQVgrkFcz3T2PKFiLocrVmW54p4ZD_fohVnec8ZoNrB3?key=540i16yY7iCYriDxUR-qlA" alt=""></td><td>Allows you to delete the selected row from the data table.</td></tr><tr><td>4.</td><td>button “Change column names and types”</td><td>Allows you to change the names and types of the columns.</td></tr></tbody></table>

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeUjTMmMSgoWZORnCZHHJ0wgN0E-V-zxYsjvRsUsACjI_qcyKjiqWoe-0WMRWRUSKxSasXhfYuY1p68xagtNUkMjusuO1OZvGvoT-x57soYNCQ8HIkuovKNYsFSPBkBCNPV7HzK-p9L7yeSdYBaBYBF4kc?key=540i16yY7iCYriDxUR-qlA" alt=""><figcaption></figcaption></figure>

In debug mode, when stepping through the script and stopping at a specific block, the current values of the variables will be displayed on the Variables panel. Thus, if a variable was not previously declared on the "Variables" panel, it will not be possible to see the current value of the variable during debugging.

If you want to use a default variable, then add it to the "Variables" panel, that is, explicitly specify the use of this variable. Assign a type and initial value to each variable. This step is not mandatory, meaning the variable will work even without being added to the "Variables" panel.

There are two types of variables:

* System variables, which already exist by default when creating a diagram;
* User-defined variables, which can be created independently.

When creating your own variables, you need to specify the data type of the new variable. Sherpa Designer uses implicit typing. This means that if you try to assign an expression or constant of a different data type to a variable, this will usually not result in an error, and the variable will automatically change its data type. However, this can lead to incorrect display of the current value of the variable on the Variables panel during debugging, as well as implicit errors in the operation of algorithms. Therefore, it is recommended to always explicitly declare and set the correct data type for the variables used.

With simple data types, the Sherpa platform performs what are called implicit conversions. For example, if you add two simple variables, the result will be a number. If you add a text variable to a numeric variable, the platform will automatically recognize that variables of different data types are being added and convert the number to text. If you decide to assign a text constant to a numeric variable, this will generally not lead to an error but to a change in the data type.

As a result of implicit conversions, not only values but even variable types can change during the execution of the script.

## **Using a Variable**

![](https://sherparpa.ru/wp-content/uploads/2024/02/2024-02-19_17-22-00.png)

If you need to pass data between different blocks, use variables, for example, set a password in one Block and check its correctness in another Block. To do this, first create a variable in the "Variables" panel. After creation, this variable can be used in the properties of any Block in this project, including in other Diagrams.

Once a variable is declared (that is, the name, type, and initial value of the variable are set on the "Variables" panel), you can assign a value to it using the Assign Variable Block. This block can also be used to assign one variable the value of another variable or to compute the result of an arithmetic expression, using mathematical, logical, string, and other functions and methods.

If you declare a variable and assign it a value enclosed in quotes, **Sherpa Designer** will treat the variable as a string: $Text = “Hello”
