In an rdlc report I want to compare integers like
if(expression)
{
// do something
}
else if(expression)
{
// do something else
}
What is the syntax for this?
Rather than using nested IIF statements I prefer the Switch statement.
From the MSDN...
=Switch(
Fields!PctComplete.Value >= 10, "Green",
Fields!PctComplete.Value >= 1, "Blue",
Fields!PctComplete.Value = 1, "Yellow",
Fields!PctComplete.Value <= 0, "Red"
)
Hope it helps :)
You will have to nest IIF statements like this:
= IIF (expression = 1, "Is 1", IIF (expression = 2, "Is 2"))
Use switch instead. I know I reached late here,but hope that it may help someone.
=Switch(Fields!Parameter.value = 2,"somethingnew", 1=1 ,"somethingelse")
1=1 refers to default in switch case.
It is similar like
if(Parameter.Value == 2)
{
somethingnew
}
else
{
somethingelse
}
This is the Syntax for your requirement:
=IIf(CInt(Fields!expression1.value)==1,true,IIf(Cint(Fields!expression2.value)==2,true,nothing))
In true part you can specify the statement to be executed.
In addition to what has been said, the If(condition, true_part, false_part) ternary operator should (with one I) be preferred over the IIf(condition, true_part, false_part) function (with two I's) in most cases.
The If() ternary operator will short-circuit evaluate only the part that corresponds to condition outcome (e.g. a condition that is True will only evaluate the true_part).
The IIf() function will always evaluate the condition and both parts, because it is just a function call and all parameters of the function will be evaluated before the call.
Since developers usually expect short-circuit evaluation in IF statements, the usage of the If() ternary operator should be the default choice.
It allows you to run expressions that check for Nothing, like the following, which would not work without lazy evaluation:
=If(Fields!Blog.Value IsNot Nothing, Fields!Blog.Value.Name, "Blog is missing")
You could also try this example
= IIF(Parameters!expression.Value = True, 'somethingnew', 'somethingelse')
Related
I have a List of objects.
importerResponse.applications is empty (size=0)
This is my code:
val isDeployed = importerResponse.applications
.flatMap(Application::instances)
.map(Instance::state)
.all { state -> DEPLOYED == state }
isDeployed is true in this case. How can this be? I want it to resolve into false if applications is empty.
Why would you want that? All the elements in the collection satisfy your predicate.
You can check the documentation:
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/all.html
If you want you can explicitly check for the collection being empty.
This should give you what you want:
val isDeployed = importerResponse.applications
.flatMap(Application::instances)
.map(Instance::state)
.count { state -> DEPLOYED == state } > 0```
The all method might be looking for any element that doesn't meet the condition, since you don't have any, it defaults to true.
You can achieve what you want by doing something similar to this:
val isDeployed = importerResponse.applications
.flatMap(Application::instances)
.map(Instance::state)
.let { it.size() > 0 && it.all { state -> DEPLOYED == state } }
Note that let allows you to reuse the same expression without recalculating it twice.
It can be a little bit confusing, why "any" returns "false" on empty collections, but "all" return true, because "all" seems to be more limiting than "any" (based on human language).
But if you ask as one example "if all persons in a room are male", than that's still true, if the room is empty. 0 out of 0 persons are ALL.
I'm just learning while doing ramda.js. Well, there are many ways to reach a goal with ramda, but there is on thing I do not understand.
I would like to check the input for an array of strings that all match one regular expression. I thought I could do it R.all(R.both(isString, isRegExp)), but it seems to deliver a true when the input is a number.
As expected R.allPass([isString, isRegExp]) gives a false with a number input.
But can anyone please explain me why R.all is returning a true? Or what and where is mistake (in thinking)?
Complete code:
var isString = R.is(String),
isMyRegExp = R.test(/^[a-z]+$/),
isMyRegExpString = R.both(isString, isMyRegExp),
isArrayOfMyRegExpStrings = R.all(isMyRegExpString),
isArrayOfMyRegExpStringsPass = R.allPass([isString, isMyRegExp]),
result = {
'all': isArrayOfMyRegExpStrings(9),
'allPass': isArrayOfMyRegExpStringsPass(9)
};
console.log(result);
// {
// all: true,
// allPass: false
// }
https://codepen.io/Eisenhardt/pen/PKLZqj
PS:
I know that I could shorten conditions with just the regexp, but there could be other situations where I need both conditions to be true. eg. isArrayOfNumber and sumOfNumbersOver50.
The second argument to R.all is expecting a list of values to test. Due to the way the function is implemented it is treating the 9 in your example as an empty list, resulting in a vacuous truth and evaluating to true.
I am trying to evaluate a text box value using SSSRS expression.
Currently I am doing something like following:
=IIF(Fields!VariableValue.Value =1,"Pass",IIF(Fields!VariableValue.Value = 2,"Fail",IIF(Fields!VariableValue.Value = 3,"Abort",IIF(Fields!VariableValue.Value = 4,"ByPass",IIF(Fields!VariableValue.Value ="#Error","NA",Fields!VariableValue.Value)))))
Is there a better way of doing this?
It's not perfect, but you can use SWITCH to make it a bit easier to read:
=Switch
(
Fields!VariableValue.Value = 1, "Pass",
Fields!VariableValue.Value = 2, "Fail",
Fields!VariableValue.Value = 3, "Abort",
Fields!VariableValue.Value = 4, "ByPass",
Fields!VariableValue.Value = "#Error", "NA"
true, Fields!VariableValue.Value
)
Looking at your example, I'm not 100% sure the original or the new expression will even work (is VariableValue a number or text?) but hopefully this is better way for you.
I have this piece of code, that checks whether a returned object is null. If so, it will return 0, or else it will return a property inside the object.
var userPoints = (from Point p in entities.Point
where p.UserName == userName
select p).SingleOrDefault();
if (userPoints == null)
{
return 0;
}
else
{
return userPoints.Points;
}
Is it possible to simplify the if statements with the nullable operator? I've tried this, but the system throws an exception when attempting to read the property
return userPoints.Points ?? 0;
No, unfortunately there's nothing which will do exactly that. Options:
Use the conditional operator:
return userPoints == null ? 0 : userPoints.Points;
Change your query to make that do the defaulting:
return (from Point p in entities.Point
where p.UserName == userName
select p.Points).SingleOrDefault();
Personally I'd go for the latter approach :) If you wanted a default other than 0, you'd need something like:
return (from Point p in entities.Point
where p.UserName == userName
select (int?) p.Points).SingleOrDefault() ?? -1;
You can do this:
var userPoints = (from Point p in entities.Point
where p.UserName == userName
select p.Point).SingleOrDefault();
return userPoints;
If there are no results then userPoints will be 0, otherwise it will be the value of Points.
You can't use it in your context.
Explanation:
You want to check whether userPoints is null, but want to return userPoints.Points if it is not null.
The ?? operator checks the first operand for null and returns it, if it is not null. It doesn't work if what you want to check and what you want to return are two different things.
Hover over var with the mouse and see what type it is.
Is it possible to do one line if statement in VB .NET? If so, how?
Use IF().
It is a short-circuiting ternary operator.
Dim Result = IF(expression,<true return>,<false return>)
SEE ALSO:
IIF becomes If, and a true ternary operator
Is there a conditional ternary
operator in VB.NET?
Orcas introduces the IF operator - a
new and improved IIF
The Ternary Operator in VB.NET
It's actually pretty simple..
If CONDITION Then ..INSERT CODE HERE..
Single line
Syntax:
If (condition) Then (do this)
Example:
If flag = true Then i = 1
Multiple ElseIf's
Syntax:
If (condition) Then : (do this)
ElseIf (condition2) Then : (do this)
Else : (do this)
End If
OR
If (condition) Then : (do this) : ElseIf (condition2) Then : (do this) : Else : (do this) : End If
Multiple operations
Syntax:
If (condition) Then : (do this) : (and this) : End If
At the risk of causing some cringing by purests and c# programmers, you can use multiple statements and else in a one-line if statement in VB. In this example, y ends up 3 and not 7.
i = 1
If i = 1 Then x = 3 : y = 3 Else x = 7 : y = 7
Or
IIf(CONDITION, TRUE_ACTION, FALSE_ACTION)
Just add Then:
If A = 1 Then A = 2
or:
If A = 1 Then _
A = 2
One Line 'If Statement'
Easier than you think, noticed no-one has put what I've got yet, so I'll throw in my 2-cents.
In my testing you don't need the continuation? semi-colon, you can do without, also you can do it without the End If.
<C#> = Condition.
<R#> = True Return.
<E> = Else Return.
Single Condition
If <C1> Then <R1> Else <E>
Multiple Conditions
If <C1> Then <R1> Else If <C2> Then <R2> Else <E>
Infinite? Conditions
If <C1> Then <R1> Else If <C2> Then <R2> If <C3> Then <R3> If <C4> Then <R4> Else...
' Just keep adding "If <C> Then <R> Else" to get more
-Not really sure how to format this to make it more readable, so if someone could offer a edit, please do-
If (X1= 1) Then : Val1= "Yes" : Else : Val1= "Not" : End If
You can use the IIf function too:
CheckIt = IIf(TestMe > 1000, "Large", "Small")
Its simple to use in VB.NET code
Basic Syntax
IIF(Expression as Boolean,True Part as Object,False Part as Object)As Object
Using IIF same as Ternary
Dim myVariable as string= " "
myVariable = IIf(Condition, True,False)
If (condition, condition_is_true, condition_is_false)
It will look like this in longer version:
If (condition_is_true) Then
Else (condition_is_false)
End If