UiPath

# Explanation of commonly used variables in UiPath and how to set them

Understanding variables is essential when developing with UiPath.

This article explains what a variable is, and the most commonly used variables String, Int32, Boolean, DateTime, Array, List, and DataTable.

＼Save during the sale period!／

Take a look at the UiPath course on the online learning service Udemy

*Free video available

This site was created by translating a blog created in Japanese into English using the DeepL translation.

Please forgive me if some of the English text is a little strange

### What is a variable?

A variable is a box that stores numbers, strings, etc.

Just as in mathematics, assigning 2 to a variable x is expressed as x=2, in UiPath we store numbers and strings in a box called x.

### Variable Types

In mathematics, we only assign numerical values to variables, but in UiPath, we can assign non-numerical values as well.

The problem is that when you try to calculate between variables, you cannot do so if a non-numeric variable is assigned to the variable.

For example, if
x=2
y=letter
-> x+y = Cannot be calculated!

If one of them has a letter in it, as in the following example, it cannot be added.

In UiPath, there is a type that indicates what is in the variable.

By specifying the type, it is possible to prevent variables from not being able to be added together as described above.

F-pen
If you don’t have programming experience, you may find it hard to understand the concept of types, but it is a concept you should keep in mind when developing with UiPath.

### Variable scope

When setting variables in Uipath, you need to determine the scope.

A scope is the range in which a variable can be used, and a variable set in the upper scope can be used in the lower scope.

Conversely, variables set in the lower scope cannot be used in the upper scope.

Setting a variable in a higher scope is convenient because it can be used in all hierarchies, but if extra variables are defined, readability is reduced and it can be a source of bugs.

sea otter
It’s better to set variables in the lower level scopes as much as possible for less trouble and better readability.

The scope is set by clicking [Variables] in the bottom row and selecting the scope for each variable.

## Commonly used single data variable types

This chapter describes the types of single data variables that are frequently used.

### String Type

To store a string in a variable, use the String type.

String is set as the default type.

Example of String type

```"abcde"
"123"
```

### Int32 Type

To store an integer in a variable, use the Int32 type.

Int32 is included in the default choices for variable types.

Int32 type example

```123
-123```

### Boolean Type

Boolean is included in the default choices for variable types.

Example of Boolean type

```True
False```

### DateTime Type

If you want to store the date and time in a variable, use the DateTime type.

Since DateTime is not included in the default variable types, set it by following the steps below.

(1)Click on [Browse for Types] for the variable type options.

(2)Enter [System.DateTime] in the search field, click [DateTime], and then click [OK].

(3)Make sure the DateTime type is set.

## Commonly used multiple data variable types

In this chapter, we will introduce the types of variables for multiple data.

As you can see in the image above, multiple variables (boxes) are combined into one variable (box), which is the type of multiple data variable.

### Array Type

If the number of elements is fixed, use the Array type (or the List type described below).

F-pen
Unlike the Array type, the List type allows you to add elements, so the List type is easier to use.

The Array type is included in the variable type defaults and is set by the following procedure.

(1) [Array of [T]] Click on

(2) Select the type to be stored in the array (in the image below, we have selected String).

(3) Click [OK].

(4) Make sure that the type of the variable is the type you set [].

Example of Array(String) type

`{"apple", "orange","banana"}`

### List Type

If the number of elements is variable, use the List type.

The List type is not included in the default variable types, so set it by following the steps below.

(1)Click the variable type pull-down, and then click [Browse for Types].

(2) Enter “System.Collections.Generic.list” in the search field and click [List<T>].

(3)Select the type in the list (String is selected in the figure below)

(4) Click [OK]

(5) Make sure it is a List<selected type>.

Example of initialization for List(String) type

```New List(of String)
```
F-pen
Be sure to initialize the List type, because you cannot add elements to it without initializing it.

Example of initializing a List(String) type and setting the initial value

```New List(of String) From{"apple", "orange","banana"}
```
sea otter
By adding From{} after New List(of String), you can set the initial value.

## tabular data

### DataTable Type

For tabular data, use the DataTable type.

The DataTable type is included in the default choices for variable types.

## Summary

• A variable is a box that stores numbers, strings, etc.
• Variables determine the scope in which they can be used.
• Variables often used in UiPath are String, Int32, Boolean, DateTime, Array, List, and DataTable.

＼Save during the sale period!／

Take a look at the UiPath course on the online learning service Udemy

*Free video available

same category UiPath

The operator of this blog, F-penIT blog

Recommended Articles
RELATED POST