Switch in a Variable

Stimulsoft Reports.NET discussion
Post Reply
whythetorment
Posts: 20
Joined: Fri Nov 20, 2009 7:40 am

Switch in a Variable

Post by whythetorment »

Hi,

How can I create a switch in a variable. I have set as a function and as readonly. Type is string

I have the following, but get an error : "Invalid expression term 'switch'.

Code: Select all

switch (DataSource1.ClaimType)
		{
			case 5:
				ToUpperCase("MyText1");
				break;
				
			case 6:
				ToUpperCase("MyText2");
				break;
				
			case 7:
				ToUpperCase("MyText3");
				break;
				
			case 8:
				ToUpperCase("MyText4");
				break;

			case 9:
				ToUpperCase("MyText5");
				break;

			case  10:         
				ToUpperCase("MyText6");
				break;

			case  11:         
				ToUpperCase("MyText7");
				break;

			default:
				DataSource1.ClaimTypeDescription;
        		break;

		}
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Switch in a Variable

Post by Edward »

Hi

In that case you need to use a ternary operation instead:

DataSource1.ClaimType == 5?"MyText1":
DataSource1.ClaimType == 6?"MyText2":"value for default"

Also that expression must be set when ReadOnly and Function checkboxes are checked in the variable editor form.

And another approach is to use custom function from the CodeTab. Please see attached report which illustrates this.

Thank you.
Attachments
281.FunctionInVariable.mrt
(15.33 KiB) Downloaded 484 times
whythetorment
Posts: 20
Joined: Fri Nov 20, 2009 7:40 am

Switch in a Variable

Post by whythetorment »

Ahhhh thank you... works like a charm..
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Switch in a Variable

Post by Edward »

Hi

Please let us know if you need any help.

Thank you.
Post Reply