# Functions in Expressions

Functions are designed for convenient manipulation of variable values within expressions. Some of the tasks that functions solve can also be addressed by separate blocks; however, using functions within expressions allows for a reduction in the number of blocks and intermediate variables in the diagram, as well as speeding up the development of robot scripts.

Sherpa RPA provides several dozen functions for performing mathematical operations, working with strings, dates and times, lists, dictionaries, and other data structures. When using a function in an expression, you need to write the function name and then specify one or more of its arguments in parentheses, which are the input data that it will work with.

To facilitate working with functions, hints have been developed. In any place where the expression editor can be invoked, the bottom of the editor window lists categories of expressions, and for each category, possible function syntax options are provided along with explanations on how to use these functions.

<figure><img src="https://3199517203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4mXXYsqBuhj7RyX6Y4Yw%2Fuploads%2Fgit-blob-62ea86eeb6809f647ff7135c1d520572de7c83d8%2Fimage%20(82).png?alt=media" alt=""><figcaption></figcaption></figure>

By double-clicking on a line in the function list, the function will appear in the editor window, allowing you to construct an expression with it:

<figure><img src="https://3199517203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4mXXYsqBuhj7RyX6Y4Yw%2Fuploads%2Fgit-blob-edcff7c58316bd4ef2746b24524516cfc5f79bc8%2Fimage%20(83).png?alt=media" alt=""><figcaption></figcaption></figure>

The function argument (located in parentheses) can be replaced with the value of any variable. In the example in the screenshot above, this is how we determine whether the value of the variable is positive or negative.

<figure><img src="https://3199517203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4mXXYsqBuhj7RyX6Y4Yw%2Fuploads%2Fgit-blob-801250339f28c60fab39eaac29a25a112058e17d%2Fimage%20(84).png?alt=media" alt=""><figcaption></figcaption></figure>

Function arguments can be any valid expressions; however, their type must correspond to the type of data that the function expects to see in that argument.

For example, the `Round()` function allows you to round the value of a number that was passed to it as an argument, that is, specified in parentheses. Instead of a number, you can specify the name of a variable that contains the desired number, or even a whole expression consisting of constants, variables, and other functions. Below are examples of correct usage of the `Round()` function.

`Round(5.5)` – will round the number 5.5 and return the result 6. Note that the decimal separator is a dot, not a comma. If you try to call the function like this: `Round(5,5)`, the result will be the number 5, not 6. This is because the comma in functions separates arguments. The program will assume that two arguments were passed to the function instead of one. This will not lead to an error, but since the `Round()` function expects only one argument, it will use the number 5 as the input value, and thus the output will also be the number 5.

`Round($MyVariable)` – if the variable $MyVariable was previously assigned the number 5.5, it will also return the value 6.

`Round($MyVariable + 5)` – following the previous example, will return the number 11.

`Round($MyVariable + Round($MyVariable))` – following the previous examples, will return the number 12.

`Round("Hello!")` – will result in an error, as the `Round()` function expects a number as an argument, not a string.

If you substitute the `Round()` function or any other function in an expression, the result of the function will be used in calculating the value of the expression at the point where you substituted the function. That is, the result of the expression “`5 + Round(5.5)`” will be 11.

A list of all available functions along with descriptions of their operation and examples of use can be found in the reference guide at the bottom of the Edit Expression window.
