if variable

Stimulsoft Reports.NET discussion
Leandro Borges
Posts: 219
Joined: Tue Oct 27, 2015 4:19 pm

if variable

Post by Leandro Borges »

Good Morning.
I created a variable and I'm trying to write an if but this returning error. The if I'm trying to do so for example:
if (field == 1)
{
        "OK";
"true";
}
else
{
        "NOK";
"false";
}

Note: I can not use the IIF as within the {} will have multiple values

Att,
Leandro Borges
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: if variable

Post by Jan »

Hello, Leandro!

If you need use this field in text expression, you can use following way:

Code: Select all

{field == 1 ? "OK" : "NOK"}
Thank you.
Leandro Borges
Posts: 219
Joined: Tue Oct 27, 2015 4:19 pm

Re: if variable

Post by Leandro Borges »

Hello, Jan!
Can you explain what that means?
Thank you.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Re: if variable

Post by Jan »

Hello, Leandro!

This is standard ternary operation from c#.

[bool-condition] ? [if-true-result] : [if-false-result]

Thank you.
Leandro Borges
Posts: 219
Joined: Tue Oct 27, 2015 4:19 pm

Re: if variable

Post by Leandro Borges »

Hello, Jan.
Thank you for explanation.
Now this returning the following error: only assignment, call, increment decrement, await, and new object expressions can be used as a statement.
Note: Example:
field == 1 ? "OK" : "NOK";
field == 2 ? "true" : "false";
Thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: if variable

Post by HighAley »

Hello, Leandro.

Maybe we don't understand your issue right.
Please, send us a sample report template with more detailed description.

Thank you.
Leandro Borges
Posts: 219
Joined: Tue Oct 27, 2015 4:19 pm

Re: if variable

Post by Leandro Borges »

Hello, HighAley.
When only leave a line, the error does not occur.
Example: campo == 1? "OK": "NOK";
When I put the two lines returns the error.
This is a control block that existed in a Crystal report.

if (Vlr_Retido != null)
{
Vlr_Retido;
}
else
{
Vlr_Retido = 0;
}

if (Vlr_Compensa != null)
{
Vlr_Compensa;
}
else
{
Vlr_Compensa = 0;
}

Vlr_Emp == ((Principal.Relação.EMP * Vlr_Base / 100) + (Principal.VLR_AUT * Principal.Relação.AUT / 100)) + Vlr_Acd;

Vlr_Emp == Vlr_Emp - Vlr_Retido;

if (Vlr_Emp < 0 )
{
diferenca == (-1) * Vlr_Emp;
Vlr_Emp == 0;
CompVrRet == False;
}
else
{
CompVrRet == True;
}

if (Vlr_Emp > 1)
{
Vlr_Emp == Vlr_Emp - Vlr_Compensa;
if (Vlr_Emp < 0 )
{
diferenca == (-1) * Vlr_Emp;
Vlr_Emp == 0;
}
else
{
diferenca == 0;
}
}
else
{
if (Vlr_Emp == 0 && Vlr_Compensa > 0)
{
diferenca == Vlr_Compensa;
}
}
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: if variable

Post by HighAley »

Hello.

Could you specify where do you use this code?
In the reports you could use any valid C# or VB.NET code.

Thank you.
Leandro Borges
Posts: 219
Joined: Tue Oct 27, 2015 4:19 pm

Re: if variable

Post by Leandro Borges »

Hello, HighAley.
I already solve, thank you.
Can I put the IF more than one condition? Example:
variavel < 0 ? variavel2 == 1; variavel3 == 2; variavel4 == 3; : variavel2 == 4; variavel3 == 5; variavel4 == 6;
Thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: if variable

Post by HighAley »

Hello.

Sorry, but you did not specify where you use this code.
If you need to set values for different variables you should use if statement. The conditional operator is not for this case.

Also your code is not right because you should use C# or VB.NET language. Which one is set in report properties?
Please, use the right assignment operator.

Thank you.
Post Reply