new Here! I'm working on Jaspersoft, I've never used it before, but I saw some guide about.
I know that the IF condition has this structure : <condition> ?(Then) True :(else) False.
But I have problem to understand this line of code (see at the end of this message), where the IF is a little bit complicated. Can someone explain me what this line of code does?
($V{REPORT_COUNT}.intValue() == (1+("".equals($P{parametriReport}.get("censimp"))?0:1)) ? ("".equals($P{parametriReport}.get("censimp"))?"":"Codice Censimp "+$P{parametriReport}.get("censimp")):"")
Related
Is there a way to determine if string does not contain something in an if statement? Basically the opposite of .contains .
Example of contains:
if someItem.contains(x) {
code
}
Example of what I am looking for:
if someItem.doesNotContain(x) {
code
}
Where a slolution for doesNotContain is what I am looking for.
Any help is greatly appreciated, thank you.
*FYI, I am new to Swift and to programming, thank you for your comments.
No Apple doesn't provide any function like doesNotContain or something similar.
But if you don't want to add else part then you can simply use:
if !someItem.contains("hello") {
//This means your someItem doesn't contain "hello" string.
}
try using this way
if !someItem.contains(x) {
code
}
Here are the results:
First off, I removed “without using a true/false Boolean” from my question in order to avoid confusion and to better suit the answer/solution.
Is there a code that is opposite to .contains? Simple Answer: NO.
It turns out that contains(_:) is a Boolean in of itself. This I did not know since I am new to coding.
The solution is actually quite simple as we can state this Boolean to be true or false, as suggested by #The Tiger.
if someItem.contains(x) == false
or
if someItem.contains(x)
Tested this, and works like a charm. Opens up a bunch of new oportunities for me, and I hope this helps out fellow coders in search of something like this.
Thank you all for your comments and helping me find the answer, Cheers.
IF IP_emo:=FALSE THEN
State:= OFF_Mode;
ELSE
State :=OFF AND IP_emo:=TRUE AND start_Btn:=TRUE OR start_Btn:=False;
State:= Monitor_Mode;
END_IF
I am not sure why I am getting error 4024 on this code requiring a := before "THEN". Can someone help me?
Disclaimer: Not sure what plc you are using or what error 4024 means but I can comment on the format of your code if you use a typcicaly IEC 61131 plc language (which most plcs are).
First, the := i an assignment operator. The = is a comparison operator. So in your if statment you would use
IF IP_emo = FALSE THEN
or alternatively (depending on which plc you use. typically all IEC 61131 languages are the same though)
IF NOT IP_emo THEN
Secondly, AND and OR are for comparison so you can't have them with an assingment operator. You can do something like
ELSE
State :=OFF;
IP_emo:=TRUE;
start_Btn:=TRUE;
start_Btn:=FALSE;
State:= Monitor_Mode;
END_IF
or maybe
ELSE
State :=OFF;
IF IP_emo=TRUE AND start_Btn=TRUE AND (start_Btn=TRUE OR start_Btn=FALSE) THEN
State:= Monitor_Mode;
END_IF
END_IF
not exactly sure what you are trying to do.
You don't mention what PLC or tool you are using, what the error 4024 means and which line it comes from. That makes it a little hard to answer your question. Some would probably say that the question qualifies for a down-wote on that account.
I'm a little confused by the formatting of your example. Please format as code (done automatically, if you use 4 spaces indent) and it will be easier to read and answer.
I made an attempt at formatting below, and have some comments to that.
Line 1: Normally you wouldn't use := but only = before THEN (might
depend on the compiler, but I doubt it)
Line 4: There's too many :='s. Should this line and the following maybe have been split into some ELSIF's or another nested IF?
I hope that helps. :-)
IF IP_emo:=FALSE THEN
State:= OFF_Mode;
ELSE
State :=OFF AND IP_emo:=TRUE AND start_Btn:=TRUE OR start_Btn:=FALSE;
State:= Monitor_Mode;
END_IF
I'm new to SQL and Postgres, so hopefully this isn't too hard to figure out for all of you.
I'm trying to use a Position function within a CASE statement, but I keep getting the error
"ERROR: Syntax error at or near ""Project"". LINE 2: CASE WHEN position('(' IN "Project") >0 THEN".
I've used this position function before and it worked fine, so I'm confused what the problem is here. I've also tried the table name, such as "xyztable.Project" and "Project" - both without quotation marks.
Here is the entire statement:
SELECT "Project",
CASE WHEN postion('(' IN "Project") >0 THEN
substring("Project",position('(' IN "Project")+1,position(')' IN "Project")-2)
CASE WHEN postion('('IN "Project") IS NULL THEN
"Project"
END
FROM "2015Budget";
As I haven't gotten to past the second line of this statement, if anyone sees anything that would prevent this statement from running correctly, please feel free to point it out.
New Statement:
SELECT "Project",
CASE
WHEN position('(' IN "Project") >0 THEN
substring("Project",position('(' IN "Project")+1,position(')' IN "Project")-2)
WHEN position('('IN "Project") IS NULL THEN
"Project"
END
FROM "2015Budget";
Thank you for your help!!
The error is due to a simple typo - postion instead of position.
You would generally get a much more comprehensible error message in situations like this (e.g. "function postion(text,text) does not exist"). However, the use of function-specific keywords as argument separators (as mandated by the SQL standard) makes this case much more difficult for the parser to cope with.
After fixing this, you'll run into another error. Note that the general form of a multi-branch CASE expression is:
CASE
WHEN <condition1> THEN <value1>
WHEN <condition2> THEN <value2>
...
END
I get the error
Variables can not be used inside bindings
on the following Drools-Rule Code
rule "minGapsBetweenAppointments"
when
$leftAssignment : AppointmentRequest(feasibleAppointment != null)
$totalValue : Number( ) from accumulate(
AppointmentRequest(feasibleAppointment != null,
$leftAssignment.requestId != requestId,
$quality : this.getOccupiedSurroundingsValue($leftAssignment)),
sum( $quality )
) // ERROR LINE
then
scoreHolder.addSoftConstraintMatch(kcontext, $totalValue.intValue());
end
Although i found this post from another question, it's not helping me much, as I need to call function getOccupiedSurroundingsValue for all other AppointmentRequests, as they're related.
Any help appreciated.
That code should work. There's nothing wrong with it as far as I can see.
Double check if you it's exactly the same as the code you're executing it. I use similar code in my examples and those work.
If it's OK, then it might be a bug in Drools Expert.
There are 2 ways to proceed:
The easy way: repost this question on the drools mailing list, maybe Edson or Wolfgang sees something I don't. Post a jira if no one sees a user-mistake.
The fastest way to solve your problem: create a new test in MiscTest that proves your case and submit it as pull request. Either you find out what you're doing wrong or you prove without a shadow of a doubt there's a bug we need to fix asap :)
I have a simple formula in crystal syntax which looks something like this :
if isdate(totext({Absence Details.Return to Work Interview Date})) = true
and {Absence Details.Return to Work Interview required} = true then
1
else
0;
This is the actual code of the formula
but the else part is never getting executed, when the condition is not true report just shows blank. I am not sure what I am doing wrong here.
Thanks in Advance.
- Amit
Maybe you have some null value in your fields - in such case crystal just returns null. You then need either "convert null values to default" setting for report or explicit testing against nulls.
Edit: NM, code was posted to the comments. Doesn't look like this is the issue.
My guess, assuming you've debugged correctly is that you've got a semicolon somewhere you shouldn't.
if {something} = x then
do something;
else
do something different;
instead of
if {something} = x then
do something
else
do something different;
This would cause the behaviour, assuming it doesn't choke on the orphaned else clause. But as the comments say, short of posting real code, we can only guess at what's going on. It could be as simple as your evaluation is always true.
Change the 0 to a 7 and see if it actually prints 7. Some report generation tools (and I have little experience with Crystal but quite a bit with others) will leave fields blank if they're zero - this often helps in reading the report by reducing unnecessary clutter.
If the 7's print out, then that's what the problem is, and it's a matter of figuring out how to get Crystal to output an actual 0.
That may be a matter of configuring the output field or even stting it to a textual "0" instead of numeric 0.
Of course, if that doesn't print out 7's, then feel free to let me know.