Crystal Reports Formula Workshop boolean condition to string - string

I'm currently trying to create a report using Crystal Reports that comes with Visual Studio 2008.
I would like to include a field of type boolean on my report that shows a string rather than true or false. The string should contain either contain a € or a % sign.
How would I go about doing this in the Formula Workshop?
I've tried things like e.g.
if {tblAankoopDetails.SoortKorting} = true then "€" else "%"
However this never seems to work and results in warnings such as "The formula result must be a number".
This should be fairly simple but this is my first go at using Crystal Reports.
Help would be much appreciated.
Jay

Make sure your SoortKorting field has always true or false. Maybe there's a null and in that case your formula will not work.
Try with this:
if isnull({tblAankoopDetails.SoortKorting} ) then
" "
else
if {tblAankoopDetails.SoortKorting} =true
then "€" else "%"

Make sure there is nothing else in the same formula. Usually I see that particular error when a formula sometimes returns a string, and sometimes a number.
Also, you shouldn't need to test for true, so you might try:
if {tblAankoopDetails.SoortKorting} then "€" else "%"

Related

Cognos Report Studio: CASE and IF Statements

I'm very new in using Cognos report studio and trying to filter some of the values and replace them into others.
I currently have values that are coming out as blanks and want to replace them as string "Property Claims"
what i'm trying to use in my main query is
CASE WHEN [Portfolio] is null
then 'Property Claims'
ELSE [Portfolio]
which is giving me an error. Also have a different filter i want to put in to replace windscreen flags to a string value rather than a number. For example if the flag is 1 i want to place it as 'Windscreen Claims'.
if [Claim Windscreen Flag] = 1
then ('Windscreen')
Else [Claim Windscreen Flag]
None of this works with the same error....can someone give me a hand?
Your first CASE statement is missing the END. The error message should be pretty clear. But there is a simpler way to do that:
coalesce([Portfolio], 'Property Claims')
The second problem is similar: Your IF...THEN...ELSE statement is missing a bunch of parentheses. But after correcting that you may have problems with incompatible data types. You may need to cast the numbers to strings:
case
when [Claim Windscreen Flag] = 1 then ('Windscreen')
else cast([Claim Windscreen Flag], varchar(50))
end
In future, please include the error messages.
it might be syntax
IS NULL (instead of = null)
NULL is not blank. You might also want = ' '
case might need an else and END at the bottom
referring to a data type as something else can cause errors. For example a numeric like [Sales] = 'Jane Doe'
For example (assuming the result is a string and data item 2 is also a string),
case
when([data item 1] IS NULL)Then('X')
when([data item 1] = ' ')Then('X')
else([data item 2])
end
Also, if you want to show a data item as a different type, you can use CAST

IF statement to determine date

I want to set an order completion date based on the words Standard or Rush.
Currently I have it set up where if a cell shows the word Standard, it will give me a date, but once I try to add Rush to that, it get errors
=IF(ISNUMBER(SEARCH("VF",B2)), IF(J2="Standard", WORKDAY(TODAY( )+2,1)), "")
I also tried this, but when I type Rush into J2, the result shows as just FALSE
=IF(ISNUMBER(SEARCH("VF",B2)), (IF(J2="Standard", WORKDAY(TODAY( )+2,1))), (IF(J2="Rush", WORKDAY(TODAY( )+1,1))))
The idea here is to make an order wanted date based on the Rush and Standard time frame.
You have embedded your new IF function inside of the wrong if.
This: (IF(J2="Standard", WORKDAY(TODAY( )+2,1))) is going to return a date or FALSE. You want to change that FALSE to return your next IF statement. Instead:
=IF(ISNUMBER(SEARCH("VF",B2)), IF(J2="Standard", WORKDAY(TODAY( )+2,1), IF(J2="Rush", WORKDAY(TODAY( )+1,1))), "")
You return nothing "" in the case that your ISNUMBER() fails still.

Conversion error If value = "" Then

I'm getting a error I can't quite explain I have a Excel list I want to load into memory, to see if the next row is still a relative row I check if the cell has a value by doing If value = "" Then but the value is 1012738 and it gives me a unhandled exception...
I can't quite understand why the code is giving a error, the cell value is formatted just like all previous cells that were checked. But here a error is thrown.
Maybe i'm just not seeing it, and someone can explain?
You should check the value each time.
Dim o As Object = oSheet.Range(xxx).Value
If (o IsNot Nothing) Then
Select Case o.GetType
Case GetType(Double)
' do work here
Case GetType(Integer)
' do work here
...
End Select
Else
...
End If
Your image isn't showing up for me.
Most exceptions in excel are datatype related. Most likely, you either have a NULL or a string that looks like an integer to the human eye. You can blindly try using trim(), int() or str() etc as needed to make sure you're actually testing an integer or matching a string if thats what you are about or you can test them in a programmatic method.
First, the programmatic method of testing ... isEmpty or isNull are needed to ensure the cell is good ...
if isEmpty(value) Then
<do something>
This will most likely catch the error which is causing the message. If empty is failing, try testing with isNull. One means the cell is empty, the other means that it wasn't initialize (rarely an issue in excel, but if using vba code it can happen).
Also ... your if statement is setup in a less than optimal... used <> in place of if then + else ...
Your code ...
If value = "" Then
General formula when you want to test that something is not something else, use the not equals ...
if value <> "value" Then
"some operation"

WorksheetFunction.value() missing in Excel

In a spreadsheet formula, =VALUE("$100") will evaluate to the numeric value of 100. I then tried to access this function in VBA via WorksheetFunction object, however it is missing.
In VBA I tried the conversion function Val("$100"), however that returns 0. So how can I accomplish this via VBA?
Val() only really works if the string is all numbers I'm afraid - currency signs cause it a problem.
If you're always going to have the same currency sign in the string, it might be worth using something like
StringName = replace(StringName, "$", "")
to take out the $ by replacing it with "" - otherwise if your strings aren't always going to be this predictable the below question might help:
How to find numbers from a string?
see https://learn.microsoft.com/en-us/office/vba/api/excel.worksheetfunction.numbervalue
example of using above, which will return a value of -1234.56:
MsgBox WorksheetFunction.NumberValue("-$1,234.56", ".", ",")
Note that if the result is non-numeric, it throws an error. For example (swapping the comma grouping and decimal character params which is invalid in this case):
MsgBox WorksheetFunction.NumberValue("-$1,234.56", ".", ",")
I don't understand why the above link doesn't have any version info. It is currently dated 2019‎-‎05‎-‎23 - no idea if that's because it is new or if it was recently updated.

Check to see if cell contains 2 spaces directly after each other

Is there a way that I can check to see if my cell contains 2 spaces immediately after one another?
For example if my cell contained "The cat went meow" then my formula below will return "No" because there is only one space between each character. However, if there where 2 spaces like
"The cat went meow"
then the formula would return "Yes".
I have tried the following formula but it picks up all the spaces instead of what I want it to do.
Can someone please show me how i could correct this?
=IF(ISNUMBER(SEARCH(" " & " ",B1)),"Yes","no")
Might be worth considering TRIM():
=LEN(B1)=LEN(TRIM(B1))
Test cases:
"The cat went meow" TRUE (single space)
"The cat went meow" FALSE (double space)
" The cat went meow" FALSE (leading space)
"The cat went meow " FALSE (trailing space)
this works for your example, if allowance is made for returning T/F rather than Y/N (to keep the formula short - Y/N could be arranged).
A better (shorter) version was offered by #Rick Hitchcock (to whom thanks) in a Comment:
=B1=TRIM(B1)
However it would return FALSE not only for "double" spaces but any quantity of spaces that are not on their own (immediately next to characters on both sides)
and
it would return FALSE even for single spaces if at the start and/or end of your string.
So this is not exactly what you asked for, and no more, but in practice seems likely to be more useful in general.
Your code works for me as-is. You could simplify it like this:
=IF(ISNUMBER(SEARCH(" ",B1)),"Yes","no")
To avoid error-checking, you could compare the string to a version with double-spaces converted to spaces, like this:
=IF(SUBSTITUTE(B1," "," ")<>B1,"Yes","no")
But I'm unsure what problem you're having with your existing code.
Try this
=IF(ISERROR(FIND(" ",B1,1)),"No","Yes")
or
=IF(ISERROR(SEARCH(" ",B1,1)),"No","Yes")

Resources