Switch Case statement else paty

Hi,

I have a requirement, like
if the value of a DT is among these values then convert the value else ignore that.
I m using a Switch case like
Switch
Expression (Row(0).toString)
Case
Default
Nothing here
CASE “A”
Assign Newvalue = “Vowel”
CASE “E”
Assign Newvalue = “Vowel”
CASE “I”
Assign Newvalue = “Vowel”
ELSE
Assign Newvalue =“Nothing”

How to do this, as if i pass the else part in default it will take every value in default clause of the switch and ignore the other conditions.

Thanks
Anil Kumar

1 Like

buddy @Anil_choudhary

You can use Switch activity to do this in uipath
like this


where you don’t need to mention the default for your case rather mention only the case conditions buddy so that would take only the case conditions to get evaluated
AND usually default will taken at last only if the switch doen’t meet any of the conditions with its case…and take the default value finally buddy @Anil_choudhary

this would give you more details buddy @Anil_choudhary

Kindly try this and let know buddy
Cheer

Hi,

Thanks a lot for prompt response,
But my Issue is I want to use the Default activity at last, but in my case its executed first and then nothing or the code is not going to next cases.
So I want it like this
If the value is A E I O U then Vowel
Else for any other value it should be “Non Vowel”

So if i pass B then it should check all the cases of A E I O U and then the default one.
but not working its directly goes to Default.

Will check this again with my DT values, might be some issue thats why always the default is executed.,
Thanks

Buddy @Anil_choudhary

Does that row(0).ToString has only one character in it… like A, E, I, O, U
or a word buddy like some names…
kindly check with the input buddy,
if its a word you can check like this in expression buddy with just one case as Vowel or with default Not a vowel
and the expression is and if think you can handle this in if condition itself buddy (only if its a word)…or you can go for the previous method of switch case if its a character…that would, but check once with the input buddy, as the condition looks good


Cheers @Anil_choudhary

1 Like

did that work buddy @Anil_choudhary

Nope, But I will check with other way around.
The thing is i need to match the values first and when nothing matches then the Default code.
But in my case its always default case and nothing else.

So let me check it again with that method and will confirm.

Yah sure buddy @Anil_choudhary

I don’t if this will still be valid, but for the sake of answering the question. When using SWITCH Activity with String Argument, you don’t need to type the Key for Cases with the qoutes. In other words, remove the qoutes (“”). Instead do it this way:

DEFAULT:
Assign Nothing
CASE A
Assign Newvalue = “Vowel”
CASE E
Assign Newvalue = “Vowel”
CASE I
Assign Newvalue = “Vowel”
CASE O
Assign Newvalue = “Vowel”
CASE U
Assign Newvalue = “Vowel”

I had the same problem, always goes to the Default Activity and skipping the Cases, found out that I had to remove the qoutes in the Cases. I guess since Switch is already defined as String in the Type Argument, so there wont be a need to put the expected values within qoutes. Hope this will help anyone having the same issue.

1 Like