Switch Statement

I’m converting some old code from Filemaker to Servoy. There is an age calculation for past due accounts that uses a Case Statement. Example:

Case(Days_Old_Calc < 30;0;(Days_Old_Calc ≥ 30) and (Days_Old_Calc < 60);1;(Days_Old_Calc ≥ 60) and (Days_Old_Calc < 90);2;(Days_Old_Calc ≥ 90) and (Days_Old_Calc < 120);3;Days_Old_Calc ≥ 120;4)

I figured I’d use a Switch Statement in Servoy, but am having trouble structuring the statement. I’ve read some other posts where people are wanting the same result for multiple cases. Example:

switch(x){
case ‘a’: code1;
break;
case ‘b’: code2;
break;
case ‘c’: code1;
break;
}

The suggestion:

switch(x) {
case ‘a’:
case ‘c’:
code 1;
break;
case ‘b’: code 2;
break;
}

I could write out several cases to cover all days from 0-29, 30-59, and so on, but what about days greater than 120? Maybe a switch statement isn’t the proper thing to use here. Thanks in advance for the help!

Not that switch is bad (although I doubt they are adequate here), but for such regular intervals, you could do something like:

var result = 0;
if (Days_Old_Calc < 120) {
	result = (Days_Old_Calc  - (Days_Old_Calc % 30)) / 30;
} else {
	result = 4;
}

Thanks Patrick!

gldni:
I could write out several cases to cover all days from 0-29, 30-59, and so on, but what about days greater than 120? Maybe a switch statement isn’t the proper thing to use here.

How about:

switch (true) {
case days <= 29:

break

case days <= 59:

break

case days <= 120:

break

default:

break
}

Hope this inspires you…