studio
2023.4
false
Studio User Guide
Last updated Nov 4, 2024

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.

  1. Create a new sequence.
  2. Create an integer variable, Number.
  3. Add an Input Dialog activity to the Designer panel.
  4. Add a Dialog Title and Input Label to prompt the user for a number.
  5. In the Value entered field, add the Number variable.
  6. Add a Switch activity, under the Input Dialog.
  7. In the Expression field, type Number mod 2. This verifies if the user’s number is divisible by 2.
  8. In the Default section, add a Write Line activity.
  9. In the Text field, type Number.ToString + " is an even number.".
  10. Click the Add new case line, and in the Case Value field, type 1.
  11. Add a Write Line activity to this case.
  12. In the Text activity, type Number.ToString + " is an odd number.".

    The final project should look as in the following screenshot.



  13. Press F5. The automation is executed. Note that the Output panel displays the data correctly.




Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.