Variables and Data Types

1. What is a Variable

Variables are containers that can hold one or multiple data entries of the same data type.

For example, the variable companyName can be a variable that holds the value "Tailent".

The value of a variable can change:

  • through an external data input

  • passing from one activity to another throughout the automation project

  • data manipulation.

2. Data Types

As we mentioned above, variables can hold data entries of the same data type, so let's see what data types are available.

TAP Automation supports all C# data types, but the most common are:

String: - tores a sequence of characters, surrounded by double quotes; e.g. "Alpha Corporation"

Integer - stores whole numbers from -2,147,483,648 to 2,147,483,647; e.g. 14

Double - stores fractional numbers. Sufficient for storing 15 decimal digits; e.g. 14.25

Boolean - stores true or false values; e.g. true

DateTime - represents an instant in time, typically expressed as a date and time of day; e.g. 12.14.2019

Other data types are collections of objects. Each object of a collection is identified through its index in the collection. Some of the most encountered collections are:

  • Array - ArrayOf<T> is used to store multiple values of the same data type. The size (number of objects) is defined at creation and can't be changed throughout the workflow. e.g. {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}

  • List - System.Collections.Generic.List<T> is used to store multiple values of the same data type, just like Arrays, but its size is dynamic, meaning that we can add or remove the object(s) from the list throughout the workflow e.g. {"Alpha Corp", "Beta Inc.", "XYZ SA"}

  • Dictionary - System.Collections.Generic.Dictionary<TKey, TValue> is used to store objects in the form of (key, value) pairs. Keys and Values can be of a separate data type. e.g.

{
{"UK", "London, Manchester, Birmingham"},
{"USA", "Chicago, New York, Washington"},
{"India", "Mumbai, New Delhi, Pune"}
}

We recommend this article about data types in C#

3. How to create a new variable

Go to the variable section and click on the + button:

A new line will appear and we have to set the variable name, value type, and default value. The first 2 are mandatory and the 3rd one is optional.

Name - It should be as descriptive as possible to make your automation easy to read by other developers or even for yourself after a while.

Variable type - select from the drop-down list the data type of your variable.

If the data type you are looking for is not in the list, click on choose type...

The window "Variable Construction - Select Type" will pop up and here you can search for the data type you are looking for, like MailMessage

Default Value - usually, variables have initial values that change throughout the automation process. If no default value is assigned when the variable is created, there is generally an Assign Value activity that sets a value afterward.