What is a Variable?

You are currently viewing What is a Variable?

A variable is defined as a name given to a computer memory location where a certain data value is stored and can be referenced. Variables also provide a way of labeling data with specific names, so that our automations can be easily read by ourselves and others. Think of a variable as a container with a label that holds a value you want to use during an automation.

A special property of variables is that the contained value inside can change, but the label for the container cannot.

Let’s look at some examples below:

Here we have three variables named Name, Status, and Amount. Each of these are different data types. When declaring variables, you need to determine the type of data that it is going to hold. This data type must be selected when declaring a variable and cannot change.

Components of a Variable

Variables are stored in memory to be used throughout your automations and can be called at any time. To call and use these variables, you use their Variable Name. The Variable Name must be determined when declaring the variable and cannot be changed during the automation.

The data inside that is passed along is called the Variable Value. This value can change throughout the automation but must match the data type of the variable holding it. For example, a Boolean variable can hold the Boolean value True, but cannot hold the integer value 441.

The Variable Type is the data type for the variable (e.g. String, Boolean, Integer). These must be selected when declaring the variable and cannot be changed during the automation.

   Note: Variables are not the values themselves, they are the containers for the values.

Changing Variables after Declaration

Now let’s say, you’re building an automation that needs to reference an employee name and the name changes every time the automation is run. To solve this, instead of changing the employee names every single time the automation is run, we can store the employee names in a string variable called Name.

In the example below, we created a string variable called Name. The first time the automation runs, the name “Nick” is added to the Name variable. The second time the automation runs, the name “Kyle” is going to replace “Nick” as variables can only hold exactly one value at a time. Now when you reference the Name variable, “Kyle” will be shown.

As Variables can only hold exactly one value at any time, there is no possible ways for a single Variable to hold multiple values. On the other hand, you can use Data Collections, which are discussed here, to gather a collection of values and store them in a systematic way.

Variables and Data Types

Both variables and the value inside must be the same Data Type.

In this example below, you can see that we cannot place the String data value “Kyle” inside the Amount variable as “Kyle” is a string and Amount is an Integer. Only Integers can fit inside an Integer Variable.

Conclusion...

In conclusion, here’s a few things to remember about variables:
  • Variables have a specific data type which must match the value inside.
  • There must always be exactly one value in a variable.
  • If you want to put a new value in a variable, the old value is replaced.
  • Any time you want to use that value, you can reference the variable, instead of the value itself.