Page 1 of 2
if variable
Posted: Tue Apr 26, 2016 12:44 pm
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
Re: if variable
Posted: Tue Apr 26, 2016 6:07 pm
by Jan
Hello, Leandro!
If you need use this field in text expression, you can use following way:
Thank you.
Re: if variable
Posted: Tue Apr 26, 2016 7:19 pm
by Leandro Borges
Hello, Jan!
Can you explain what that means?
Thank you.
Re: if variable
Posted: Tue Apr 26, 2016 7:23 pm
by Jan
Hello, Leandro!
This is standard ternary operation from c#.
[bool-condition] ? [if-true-result] : [if-false-result]
Thank you.
Re: if variable
Posted: Wed Apr 27, 2016 12:57 pm
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.
Re: if variable
Posted: Wed Apr 27, 2016 1:01 pm
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.
Re: if variable
Posted: Wed Apr 27, 2016 1:15 pm
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;
}
}
Re: if variable
Posted: Wed Apr 27, 2016 1:40 pm
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.
Re: if variable
Posted: Wed Apr 27, 2016 2:04 pm
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.
Re: if variable
Posted: Wed Apr 27, 2016 2:37 pm
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.