How to use operators (+,-,/,*) as switch options in switch

I tried using normal switch with Operators as case Like this

Var3 get populated from excel either +,-,*,/

while debugging I have noticed switch case is not working

Expression Var3

Case “+”
Varint4 = Varint1 + Varint 2

Case “-”
Varint4 = Varint1 - Varint 2
Case “*”
Varint4 = Varint1 * Varint 2
Case “”
Varint4 = Varint1 \ Varint 2

@Ritik Change the type argument as String in Switch case activity.

1 Like

@Ritik Remove the “” from “+” if having argument as string. Apply it on all cases.

Your switch case should looks like this

Hi @Divyashreem, @Emman_Pelayo,

Thanks for reply.

I tried putting Cases like shown in screenshot by Divya, However Switch is not recognizing any of the operators.

Regards,
Ritik

@Ritik Add a default case, then writeline your argument so you can compare.

Before passing those to cases you should convert that as string then pass them in condition.

Hi @Emman_Pelayo,

Thanks for quick reply.

I got the issue, actually in Excel from where was reading data all operators were stored leading with Space .

For Example
" +" ," -"," *"," /"

Hence I used trim and it worked

Var3 = Trim (row(0).Tostring)

Expression Var3

Case +
Varint4 = Varint1 + Varint 2
Case -
Varint4 = Varint1 - Varint 2
Case *
Varint4 = Varint1 * Varint 2
Case
Varint4 = Varint1 \ Varint 2

Thanks all for reply.
Regards,
Ritik

2 Likes