I have written a formula to return a string based on logic run on a string field in my database. I have everything working, except I'm unable to return when the field is the empty string.
This is what I need:
...
else if ({TABLE.FIELD} = "") then
"Fixed"
...
However, this entry appears as the empty string in my report. I've tried testing the length of the field to 0 and the StrCmp functions. Nothing seems to work. Google results state that a simple comparison to "" or '' should make the logic work. I am new to CR, so maybe I am missing something. Any ideas on how I can acquire this functionality?
You can check for IsNull condition. Although it should be obvious from the answer, you want to check for NULL as your first check, since Crystal Reports is picky about handling nulls. @numerah If IsNull({Table.
Symptom. IIF and IsNull are functions in Crystal Reports that are used in formulas to test fields for blanks, empty strings, missing values and NULL, then return some valid output. This is especially helpful when preparing a report, since these values can cause blank lines to be printed.
@michaelg The purpose of NOT ISNULL is to determine, true or false, should I update the shared variable? If value isn't null, your code should put it into the shared variable. If it is null, your code can safely ignore it and do nothing.
Crystal Reports may return odd results with string formulas that may encounter a database field containing a null value (a special database value equating to empty, as opposed to zero for a number field, or an empty string for a string/text field).
It's been a long while since I used Crystal, but are you sure it's actually empty and not null? If I recall correctly, Crystal does a very poor job of handling null values, and they must be checked first; check to see if the string is a null as your very first test and display "Fixed", see if that clears things up.
When you enclose the numbers in quotation marks, Crystal Reports interprets the values in the formula as strings, not numbers. When you use a plus sign or ampersand with strings, the result is the concatenation of the individual string elements.
In Crystal formulas there is a dropdown at the top of the screen which asks if you want to "use default values for NULL" or "exceptions for NULL". It is often easier to use default values (you don't then have to check for NULL).
You can check for IsNull condition.
If IsNull({TABLE.FIELD}) or {TABLE.FIELD} = "" then
// do something
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With