How to use variable as the case of "switch activity"

I am trying to use switch activity for case VarA, VarB and VarC inside switch activity but it not working. Please advise on how to achieve the following result.

Assign Var A = “Apple”, Var B = “Banana”, Var C = “Cat”
Assign Var D = “Apple”

*** I am using Var A,B,C,D as I want to make the case dynamic

Switch: Var D
Case: Default —> write 0
Case: Var A --> write 1
Case: Var B --> write 2
Case: Var C --> write 3

I want the answer to be “write 1” instead of “write 0”.

1 Like

Buddy @RoboticKK
you can do like buddy either that you can pass the variable as expression and value as case buddy

But when you try to pass the variable to case it wont work buddy as CASE CAN ONLY TAKE OBJECTS, NOT VARIABLES…
this could help you buddy
https://syntaxdb.com/ref/csharp/switch
even if you try you will get like this buddy
image

Cheers @RoboticKK

1 Like

I’d switch it around if I were you.

Have the Switch as a variable which could be any of the items (Apple, Banana, Cat)

Then each case in the switch would be:
Default --> write 0
Case: Apple --> write 1
Case: Banana --> write 2
Case: Cat --> write 3

Don’t forget to change the switch properties TypeArgument to String

The situation is both the switch expression and the case are variables

Hi there,

Slight correction to everyone’s answers here…

I have found that as the type argument is changed to string that is being passed in every case, you will have to give Apple, Banana and Cat without the quotes. here you go :slight_smile:

And the workflow for your reference : Main.xaml (5.3 KB)

Hope this solves your query

Regards

1 Like

Oh my you are a GENIUS! Saved me over an hour of headaches trying to figure this out. THANK YOU! :slight_smile: