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.
- Create a new sequence.
- Create two Int32 variables,
BirthYear
andAge
. The first stores the user’s birth year and the second, the user’s age. - Add an Input Dialog activity to the sequence.
- In the Properties window, type an appropriate title and label.
- In the Result field, add the
BirthYear
variable. - Add an Assign activity under the Input Dialog.
- In the Properties panel, in the To field, add the
Age
variable. - In the Value field, type
2019 – BirthYear
. This assigns the value of the subtraction (2019 minus the user’s birth year) to theAge
variable. - Add a Message Box activity under the Assign one.
- In the Properties panel, in the Text field, type "Congratulations! You are " +
Age.ToString
+ ".".
Note:
The
.ToString
method converts the integer stored in theAge
variable to a string and displays it as such.
The final project should look as in the following screenshot.
- Press F5. The automation is executed. Note that the Message Box displays your age, as expected.
Updated 3 years ago