# Switch case to check range of number

Hi, I would like to use the switch case to check a number between two range inside each case.
Check the below image, I am getting error. Not able to do this. Please share your suggestons.

1 Like

Fine we can check like this
In expression be like
Convert.ToDouble(in_amount) > 78 And Convert.ToDouble(in_amount) < 4557

And in case mention as True and another case with value as False

Cheers @sarathi125

2 Likes

@sarathi125

As the error is mentioning Case value should be a double.

It depends on your requirements, but give a try to implement a mapping logic to assig a number to certain class/segment/category (name it as you feel ok) and then use this segment value in the switch activity

hey @sarathi125

You can check like this

Convert.ToDouble(in_amount) >= 78 And Convert.ToDouble(in_amount) <= 4557

And in case mention as True and another case with value as False

or if you are having more ranges then you can opt for nested if else.

Regardsâ€¦!!
Aksh

1 Like

I need to check that amount range from 1-5000,
5000-10000, 10000>. Three cases should be used. Not only two.

1 Like

Hey Yes so it is not much cases so you can easily use if Activity here.

Regardsâ€¦!!
Aksh

Yeah, then I have to use three if statements. If we have this switch similar to VB.nwt select then only one switch actually. Will check

1 Like

Yah we can use this expression in switch expression as input
IF (Convert.ToDouble(in_amount) > 1, â€śGreater than 1
IF(Convert.ToDouble(in_amount) < 5000, â€śLesser than 5000â€ť,
IF(Convert.ToDouble(in_amount) > 5000, â€śGreater than 5000â€ť,
IF(Convert.ToDouble(in_amount) < 10000,â€ťLesser than 10000â€ť,
IF(Convert.ToDouble(in_amount) > 10000,â€ťGreater than 10000â€ť,
â€śLess than 1â€ť)))))

And mention the string mentioned above in the cases as value like Greater than 1 for case1, Lesser than 500 for case2â€¦ it goes on

Cheers @sarathi125

4 Likes

@sarathi125
Have a look on Integer Division

Int Division Operator:
amount 1 - 5000 Int Division 5000 = 0
amount 5000 - 10000 Int Division 5000 = 1
â€¦
amount greater then 10000 Int Division 5000 is default case in the switch

Buddy check it out this attachment

SelectSwitchVb.xaml (4.2 KB)

Cheers

Regardsâ€¦!!
Aksh

3 Likes

With this case can you output the result in arguments too? And use a varibale threshold? Iâ€™m imagining with input as double:

Select Case inAmount
Case 0 To lowThreshold
out=â€ślowâ€ť
Case lowThreshold To highThreshold
out=â€śmidâ€ť
Case >highThreshold
out=â€śhighâ€ť
End Select

Would this work?

The â€śCase valueâ€ť can be only a constant value.
Not range, not variable.
This is the limitation of the activity

Cheers

2 Likes

Hey @SoqedHozi

Off course it will

It is possible just in case when you do not want to consider Optimization as a factor