# Types of Variables

> A text or string variable is a type of variable that can store only [strings](https://en.wikipedia.org/wiki/String_%28computer_science%29). These types of variables can be used to store any information such as employee names, usernames or any other string.

## Text Variables

A text or string variable is a type of variable that can store only [strings](https://en.wikipedia.org/wiki/String_%28computer_science%29). These types of variables can be used to store any information such as employee names, usernames or any other string.

:::note
All strings in UiPath have to be placed in between quotes.
:::

### Example of Using a Text Variable

To exemplify how you can work with text variables, we are going to create a project that asks for the user’s name, stores it and displays only the first letter of his name in the **Output** panel.

1. Create a sequence.
2. Create two simple string variables, `FullName` and `FirstLetter`.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-168245-49a4bc73.webp)

3. Add an [Input Dialog](https://docs.uipath.com/activities/docs/input-dialog) activity to the **Designer** panel.
4. In the **Input Label** field, type "Type your full name please.".
5. In the **Dialog Title** field, type "What is your name?".
6. In the **Value entered** field, add the `FullName` variable. This variable stores whatever the user writes when prompted with the **Input Dialog** activity.
7. Add an [Assign](https://docs.uipath.com/activities/docs/assign) activity under the **Input Dialog** one.
8. In the **Properties** panel, in the **To** field, add the `FirstLetter` variable.
9. In the **Value** field, type `FullName.Substring(0,1)`. The `FirstLetter` variable is assigned the new value created by the `FullName.Substring(0,1)` expression.

      :::note
      This field uses the `Substring()` function to find the first character from the string added by the user in the **Input Dialog**.
      :::

10. Add a [Write Line](https://docs.uipath.com/activities/docs/write-line) activity under the **Assign** one.
11. In the **Properties** panel, in the **Text** field, enter the `FirstLetter` variable. This means that the **Output** panel is going to display the first letter of what the user wrote in the **Input Dialog**. The project should look as in the following screenshot.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-167857-e7da8c41.webp)

12. Press F5. The **What is your name?** window is displayed.
13. Type your name in the text field and click **OK**. In **UiPath Studio**, in the **Output** panel, note that the first letter of your name is displayed.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-168805-8d0a7bc4.webp)

[Download example](https://documentationexamplerepo.blob.core.windows.net/examples/Studio_v2022.10/TextVariables.zip)

## True or False Variables

The true or false variable, also known as boolean, is a type of variable that only has two possible values, true or false. These variables enable you to make decisions, and thus have a better control over your flow.

### Example of Using a True or False Variable

To exemplify how you can work with true or false variables, we are going to create an automation that asks the user for his name and gender, and displays the results in another window.

1. Create a new process and add a **Flowchart**.
2. Create two string variables, `Name` and `Gender`. The first is going to be used to store the name of the user, and the second to store the user’s gender.
3. Create a boolean variable, `Male`. This variable is going to be used to verify if the user is a male.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-172572-13b4e4c5.webp)

4. Add an [Input Dialog](https://docs.uipath.com/activities/docs/input-dialog) activity to the **Designer** panel and connect it to the **Start** node.
5. In the **Properties** panel, in the **Label** field type "What is your name?".
6. Add a title and, in the **Result** field, add the `Name` variable.
7. Add another **Input Dialog** activity and connect it to the previous one.
8. In the **Properties** panel, in the **Label** field, type "What is your gender?".
9. Add a title and, in the **Result** field, add the `Gender` variable.
10. Add a [Flow Decision](https://docs.uipath.com/activities/docs/flow-decision) activity to the **Designer** panel, and connect it to the second **Input Dialog**.
11. In the **Properties** panel, in the **Condition** field, type `Gender` = "Male" or `Gender` = "male". This activity checks if the user is a male or female.
12. Add two [Assign](https://docs.uipath.com/activities/docs/assign) activities.
13. Connect one to the **True** branch of the **Flow Decision** activity.
14. In the **Properties** panel, in the **To** field enter the `Male` variable.
15. In the **Value** field, type **True**. This assigns the **True** value to the `Male` variable when the `Gender` = "Male" or `Gender` = "male" condition is met.
16. Connect the second **Assign** activity to the **False** branch of the **Flow Decision**.
17. In the **Properties** panel, in the **To** field, enter the `Male` variable.
18. In the **Value** field, type **False**. This assigns the **False** value to the `Male` variable when the `Gender` = "Male" or `Gender` = "male" condition is not met.
19. Add a new **Flow Decision** and connect the previously added **Assign** activities to it.
20. In the **Properties** panel, in the **Condition** field, type `Male` = True.
21. Add a [Message Box](https://docs.uipath.com/activities/docs/message-box) activity and connect it to the **True** branch of the **Flow Decision**.
22. In the **Properties** panel, in the **Text** field, type `Name` + " is a " + `Gender` + ".". This message displays the name of the user and its gender, if `Male` is true.
23. Add another **Message Box** activity and connect it to the **False** branch of the **Flow Decision**.
24. In the **Properties** panel, in the **Text** field, type `Name` + " is a " + `Gender` + ".". This message displays the name of the user and its gender, if `Male` is false. The final project should look like in the following screenshot.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-169017-3e6fd6fd.webp)

25. Press F5. The automation is executed. Note that the final **Message Box** displays the message as expected.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-167757-0748f1f6.webp)

[Download example](https://documentationexamplerepo.blob.core.windows.net/examples/Studio_v2022.10/TrueOrFalseVariables.zip)

## Number Variables

Number variables are also known as integer or Int32, and are used to store numeric information. They can be used to perform equations or comparisons, pass important data, and many others.

### Example of Using a Number Variable

To exemplify how you can work with number variables, we are going to create an automation that asks the user for the year in which he or she was born and displays the age in a window.

1. Create a new sequence.
2. Create two Int32 variables, `BirthYear` and `Age`. The first stores the user’s birth year and the second, the user’s age.
3. Add an [Input Dialog](https://docs.uipath.com/activities/docs/input-dialog) activity to the sequence.
4. In the **Dialog Title** and **Input Label** fields, type an appropriate title and label.
5. In the **Value entered** field, add the `BirthYear` variable.
6. Add an [Assign](https://docs.uipath.com/activities/docs/assign) activity under the **Input Dialog**.
7. In the **Properties** panel, in the **To** field, add the `Age` variable.
8. In the **Value** field, type `2022 – BirthYear`. This assigns the value of the subtraction (2022 minus the user’s birth year) to the `Age` variable.
9. Add a [Message Box](https://docs.uipath.com/activities/docs/message-box) activity under the **Assign** one.
10. In the **Properties** panel, in the **Text** field, type "Congratulations! You are " + `Age.ToString` + ".".

        :::note
        The `.ToString` method converts the integer stored in the `Age` variable to a string and displays it as such.
        :::

    The final project should look as in the following screenshot.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-168957-3820f59a.webp)

11. Press F5. The automation is executed. Note that the **Message Box** displays your age, as expected.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-168061-d86823a5.webp)

[Download example](https://documentationexamplerepo.blob.core.windows.net/examples/Studio_v2022.10/NumberVariables.zip)

## Array Variables

The array variable is a type of variable which enables you to store multiple values of the same type.

UiPath Studio supports as many types of arrays as it does types of variables. This means that you can create an array of numbers, one of strings, one of boolean values and so on.

### Example of Using an Array Variable

To exemplify how you can work with array variables, we are going to create an automation that asks the user for his first and last name and age, stores the information in an array and then writes it in a `.txt` file.

1. Create a new sequence.
2. Create three string variables, `FirstName`, `LastName` and `Age`, in which to store the information gathered from the user.
3. Create an array of strings variable called `NameAge`.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-167425-4baf749f.webp)

4. Add an [Input Dialog](https://docs.uipath.com/activities/docs/input-dialog) activity to the **Designer** panel.
5. Fill in the **Dialog Title** and **Input Label** fields to ask for the user’s first name.
6. In the **Value entered** field, type the `FirstName` variable. This variable stores the first name of the user.
7. Add another **Input Dialog** activity under the previous one.
8. Fill in the **Dialog Title** and **Input Label** fields to ask for the user’s last name.
9. In the **Value entered** field, type the `LastName` variable. This variable is going to store the last name of the user.
10. Add another **Input Dialog** activity under the previous one.
11. Fill in the **Dialog Title** and **Input Label** fields to ask for the user’s age.
12. In the **Value entered** field, type the `Age` variable. This variable is going to store the age of the user.

        :::note
        We use a string variable and not an integer to store the age, so that we do not have to convert it later on, when we add it to the string array variable.
        :::

13. Add an [Assign](https://docs.uipath.com/activities/docs/assign) activity under the last **Input Dialog**.
14. In the **Properties** panel, in the **To** field, type the `NameAge` variable.
15. In the **Value** field, type {`FirstName`,`LastName`,`Age`}. This **Assign** activity enables you to store all the values from the initial string variables in the `NameAge` one.
16. Add a [Write Text File](https://docs.uipath.com/activities/docs/write-text-file) activity under the **Assign** one.
17. In the **Properties** panel, in the **FileName** field, type the path of the file you want to write to between quotation marks, such as `"%HOMEPATH%\Desktop\array_variable.txt"`.

        :::note
        If the file does not exist at the provided path, it is created.
        :::

18. In the **Text** field, type `NameAge(0)` + " " + `NameAge(1)` + " " +`NameAge(2)` + " ".

        :::note
        By adding the index number of the array items you can access their values and write them, in this example, to a text file.
        :::

    The final project should look as in the following screenshot.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-168829-38b653ec.webp)

19. Press Ctrl + F5 to run the project.
20. Navigate to the file provided at step 17 and double-click it. A **Notepad** window is displayed with the information you added at step 20.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-168165-a2bd791f.webp)

[Download example](https://documentationexamplerepo.blob.core.windows.net/examples/Studio_v2022.10/ArrayVariables.zip)

## Date and Time Variables

The date and time variable is a type of variable that enables you to store information about any date and time. This type of variable can be found in the **Browse and Select a .Net Type** window, under the System namespace `System.DateTime`. For more information, see [Browsing for .Net Variable Types](https://docs.uipath.com/studio/standalone/2024.10/user-guide/managing-variables#managing-variables).

For example, they can be used to append dates to invoices or any other documents you may be working with and are time-sensitive.

### Example of Using a Date and Time Variable

To exemplify how you can work with a date and time variable, we are going to build an automation that gets the current date and time, subtracts a specific amount of time and writes the result to a Microsoft Excel spreadsheet.

1. Create a new sequence.
2. Create two DateTime variables, `Today` and `LastTime`.
3. Create a TimeSpan variable, called `Span`, and in the **Default** field type `1.02:10:04`.

      :::note
      The default value attributed to the`Span` variable uses the day.hh:mm:ss format.
      :::

4. Add an [Assign](https://docs.uipath.com/activities/docs/assign) activity to the **Designer** panel.
5. In the **Properties** panel, in the **To** field, add the `Today` variable.
6. In the **Value** field, type `Now`. This gives you the date and time when the project is executed, in the `dd/MM/yyyy` and `hh:mm:ss` formats.
7. Add another **Assign** activity under the previous one.
8. In the **Properties** panel, in the **To** field, add the `LastTime` variable.
9. In the **Value** field, type `Today.Subtract(Span)`. This is going to subtract the default value of the `Span` variable from the current date, stored in the `Today` variable.
10. Add an [Excel Process Scope](https://docs.uipath.com/activities/docs/excel-process-scope-x) activity under the last **Assign** one. This activity opens or reuses Excel processes, loads the Excel project settings, and applies them to the associated Excel file.
11. Add a [Use Excel File](https://docs.uipath.com/activities/docs/excel-application-card) activity inside the **Excel Process Scope** activity.

        :::note
        Use the [Manage Packages](https://docs.uipath.com/studio/standalone/2024.10/user-guide/managing-activities-packages#managing-packages) feature to download the Excel activities, if you do not already have them installed.
        :::

12. In the **Workbook path** field, type the path of the Excel file you want to write to, between quotation marks. In our case, `"%HOMEPATH%\Desktop\urgent_invoice.xlsx"`.

        :::note
        If the file does not exist at the provided path, it is going to be created.
        :::

13. Add a [Write Cell](https://docs.uipath.com/activities/docs/write-cell-x) activity in the **Use Excel File** activity.
14. In the **What to write** field, type `LastTime.ToString`. This transforms the value of the `LastTime` variable to a string and writes it to the coordinates previously given.

15. On the right side of the **Where to write** field, select **Plus** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-plus_menu-8a20ac7d.png) &gt; **Excel** &gt; **Indicate in Excel**.

16. Inside the Excel file, indicate the cell in which you want to write (in our case, "E3"). Click **Confirm** after indicating the cell.

The final project should look as in the following screenshot:

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-166740-814a08a0.webp)

17. Press F5. The automation is executed.
18. Navigate to your Excel file and double-click the cell in which you added the date. Note that the time and date information is displayed in the cell you pointed towards.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-167045-874ea11d.webp)

[Download example](https://documentationexamplerepo.blob.core.windows.net/examples/Studio_v2022.10/DateAndTimeVariables.zip)

## Data Table Variables

DataTable variables represent a type of variable that can store big pieces of information, and act as a database or a simple spreadsheet with rows and columns. They can be found in the **Browse and Select a.Net Type** window, under the System.Data namespace (System.Data.DataTable). For more information, see [Browsing for.Net Variable Types](https://docs.uipath.com/studio/standalone/2024.10/user-guide/managing-variables#managing-variables).

These variables can be useful to migrate specific data from a database to another, extract information from a website and store it locally in a spreadsheet and many others.

### Example of Using DataTable Variables

To exemplify how you can use DataTable variables, we are going to create an automation that reads only two out of multiple columns from an Excel spreadsheet, and then transfers them to another spreadsheet that already contains other information.

The initial file is a database of people, transactions, dates, and products. In this example, we are going to extract their names and order dates and append them to an Excel spreadsheet that already contains similar information.

1. Create a new sequence.
2. Add an [Excel Process Scope](https://docs.uipath.com/activities/docs/excel-process-scope-x) activity. This activity opens or reuses Excel processes, loads the Excel project settings, and applies them to the associated Excel file.
3. Add a [Use Excel File](https://docs.uipath.com/activities/docs/excel-application-card) activity to the sequence. This activity is required for most of the Excel-related activities.

      :::note
      If you do not have Excel activities installed on your version of UiPath, use the [Manage Packages](https://docs.uipath.com/studio/standalone/2024.10/user-guide/managing-activities-packages#managing-activity-packages) functionality to get them.
      :::

4. Create two DataTable variables, `dt_NamesList` and `dt_DateInfo`. These are going to be used to store information from the initial Excel spreadsheet.
5. In the **Properties** panel, in the **Workbook path** field, type the path of the initial Excel file to be used, between quotation marks.
6. Add two [Read Range](https://docs.uipath.com/activities/docs/read-range-x) activities and place them one under the other, in the **Use Excel File** activity. These are used to get information from the initial spreadsheet.

7. Select the first **Read Range** activity. On the right side of the **Range** field, select **Plus** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-plus_menu-8a20ac7d.png) &gt; **Excel** &gt; **Indicate in Excel**.

8. Inside the Excel file, indicate the coordinates that tell UiPath Studio from where to extract information (in our case, "G7:G37"). Click **Confirm** after selecting the range.
9. In the **Save to** field, type the name of the first DataTable variable, `dt_NamesList`. This variable stores all the information available between the G7 and G37 rows.
10. (**Optional**) Change the value in the **DisplayName** field to Read Names, so you can easily tell apart this activity from the second one.

11. Select the second **Read Range** activity. On the right side of the **Range** field, select **Plus** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-plus_menu-8a20ac7d.png) &gt; **Excel** &gt; **Indicate in Excel**.

12. Inside the Excel file, indicate the coordinates that contain the order date we want to extract (in our case, "C7:C37"). Click **Confirm** after selecting the range.
13. In the **Save to** field, specify the `dt_DateInfo` variable. This variable retains all the date information we require.
14. Add a second [Use Excel File](https://docs.uipath.com/activities/docs/excel-application-card) activity to the sequence.
15. In the **Properties** panel, in the **Workbook path** field, type the path of the Excel file to be used to store all the information gathered at the previous steps.
16. Add a [Write DataTable to Excel](https://docs.uipath.com/activities/docs/write-range-x) activity to the **Designer** panel, under the second **Use Excel File**. This activity is used to write the stored information to another Excel file.

        :::note
        The file used with the **Write Range** activity has to be closed when you run the project. If it is not closed, an error is displayed and the automation execution stops.
        :::

17. In the **What to write** field, type the `dt_NamesList` variable.

18. On the right side of the **Destination** field, select **Plus** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-plus_menu-8a20ac7d.png) &gt; **Excel** &gt; **Indicate in Excel**.

19. Inside the second Excel file, select the starting cell in which information from the initial file is to be added (in our case, "B7"). Click **Confirm**.
20. Add another **Write DataTable to Excel** activity and place it under the first one.
21. In the **What to write** field, type the `dt_DateInfo` variable.

22. On the right side of the **Destination** field, select **Plus** ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-plus_menu-8a20ac7d.png) &gt; **Excel** &gt; **Indicate in Excel**.

23. Select the starting cell (in our case, "A7"). Click **Confirm**.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-171204-a5242388.webp)

24. Press F5. Your automation is executed.
25. Double-click the final Excel file. Note that the copied information is available, and correctly updated.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/studio/2024-10-docs-image-172588-d345deae.webp)

[Download example](https://documentationexamplerepo.blob.core.windows.net/examples/Studio_v2022.10/DataTableVariables.zip)
