Common Data Types and Conversion in UiPath Studio

What are data types?

As you can guess by the name, data types describe the kind of data a variable can hold. For example, if the data type is Int32, then the variable must hold an integer. Likewise, if the data type is a String, then the variable must hold a text.

Data types

Listed below are some of the most commonly used ones.

System.String

System.String stores texts. This type of data comes with many methods of data manipulation that will be explained in detail in another lesson, namely Data Manipulation with Strings in Studio.

Numeric(category)

 

These variables store numbers. There are different sub-types of numerical variables. For example:

  • Int32 - System.Int32 (signed integers): 10, 299, -100
  • Long - System.Int64 (long integers): 54354353430, -11332424D
  • Double - System.Double (allows decimals, 15-16 digits precision): 19.1234567891011

System.Boolean 

stores one of two value:  True or False

Collection(category)

Collections are largely used for handling and processing complex data. Some of the most encountered collections are:

  • Array - ArrayOf<T> or System.DataType[] stores multiple values of the same data type. The size (number of objects) is defined at creation.
  • List - System.Collections.Generic.List<T> stores multiple values of the same data type, just like Arrays. But unlike Arrays, the size is dynamic.
  • Dictionary - System.Collections.Generic.Dictionary<TKey, TValue> stores objects in the form of (key, value) pairs, where each of the two can be a separate data type.

DataTable 

represents variables that can store big pieces of information and act as a database or a simple spreadsheet with rows and columns.

Date and Time(category)

  • DateTime - System.DateTime stores specific time coordinates (mm/dd/yyyy hh:mm:ss).
    This kind of variable provides a series of specific processing methods like subtracting days, calculating time remaining vs. today, and so on.

    For example, to get the current time, assign the expression DateTime.Now to a variable of type DateTime.
  • TimeSpan - System.TimeSpan stores information about a duration (dd:hh:mm:ss). You can use it to measure the duration between two variables of the type DateTime.

    For example, you can save the time at the start of the process in one variable (of type DateTime), the time at the end in another (of type DateTime) and store the difference in a variable of type TimeSpan.

Conversion methods of Data Types

There will be scenarios where we'll need to change the data type of a variable to another form. For example, the conversion of an integer to a string or vice versa. In such cases, we can use the conversion methods available in Studio.

Below is a list of some of the most commonly used conversion methods.

Convert.ToString Method

This method converts the specified value to its equivalent string representation. For example, from an integer to String.


 Eg: StrVar = Convert.Tostring(IntVar)

 

Convert.ToInt32 Method

This method converts a specified value to an integer. For example, from a String to integer or from a floating-point number to integer.


Eg: 

IntVar = Convert.ToInt32(StrVar)

IntVar = Convert.ToInt32(DblVar) 


There's another method to convert a string to an integer - CInt(String)


Eg: IntVar = CInt(StrVar)

 

Double.ToString Method

 

This method converts the numeric value of a floating-point number to its equivalent string representation. 


Eg: StrVar = DblVar.ToString

 

Double.Parse Method

This method converts the string representation of a number to its floating-point number equivalent.


Eg: DblVar = Double.Parse(StrVar)

 

Boolean.ToString Method

This method converts the value of a Boolean to its equivalent string representation (either "True" or "False"). 


Eg: ToString()

 

Convert.ToBoolean Method

This method converts a specified value to an equivalent Boolean value. For example, coveting an integer to an equivalent Boolean value. 


Eg: Convert.ToBoolean(IntVar)

Convert Date and Time to String

This method converts the value of the specified DateTime object to its equivalent string representation.  

Eg: DateTimeVar.ToString("dd-MM-yyyy")

Most of the data types used in UiPath are borrowed from the Visual Basic.NET language and there are several methods to convert a data type from to another.

 

 Source: UiPath Academy