Example of Using a Switch Activity
To exemplify how to use the Switch activity, we are going to create an automation that asks the user for a number, checks if is odd or even, and depending on that, a different message is written to the Output panel.
Since all odd numbers divided by two have a remainder equal to 1, this project needs only two cases (0 and 1), yet keep in mind that this activity supports multiple cases.
-
Create a new sequence.
-
Create an integer variable,
Number. -
Add an Input Dialog activity to the Designer panel.
-
Add a Dialog Title and Input Label to prompt the user for a number.
-
In the Value entered field, add the
Numbervariable. -
Add a Switch activity, under the Input Dialog.
-
In the Expression field, type
Numbermod 2. This verifies if the user’s number is divisible by 2. -
In the Default section, add a Write Line activity.
-
In the Text field, type
Number.ToString+ " is an even number.". -
Click the Add new case line, and in the Case Value field, type 1.
-
Add a Write Line activity to this case.
-
In the Text activity, type
Number.ToString+ " is an odd number.". The final project should look as in the following screenshot.
-
Press F5. The automation is executed. Note that the Output panel displays the data correctly.

