?
Solved

Trying to Display Checkbox on Crystal Report

Posted on 2009-04-02
25
Medium Priority
?
1,227 Views
Last Modified: 2012-05-06
I am trying to display a checkbox on a crystal report in a string field.  After doing some searching I found a solution that involved adding the following formula:

if {RComment1.C8}="0" then "256" else "168"

I have set the field font to Wingdings and the formula seems to compile without errors; however, when I try to run it I get the following error:

A number is required here.
Error in File c:\temp\temp_5889 .....  671}.rpt:
Error in formula <Css_Class_Text>
'if {RComment1.C8}="0" then "256" else "156"
'
A number is required here.

I am new to crystal reports and would appreciate any help.
0
Comment
Question by:Bartman88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 5
  • +1
25 Comments
 
LVL 35

Expert Comment

by:James0628
ID: 24055888
Where are you using that formula?  If you're simply putting it on the report, it would simply output the string "256" or "168", which presumably wouldn't give you what you want.

 Is RComment1.C8 numeric or string or ...?  If it's numeric, you'd get that error because you're trying to compare it to a string ("0").  If it's string, then the formula is syntactically fine, in which case the error must be because of where you're using the formula (ie. the formula outputs a string, but you're using it in a place where a number is expected).

 James
0
 
LVL 35

Expert Comment

by:James0628
ID: 24055897
Oh.  I just noticed this.

 You said that the formula that you're using is:

if {RComment1.C8}="0" then "256" else "168"

 But the formula in your error is:

if {RComment1.C8}="0" then "256" else "156"


 One has 168 and the other has 156.  Are they really different?

 James
0
 

Author Comment

by:Bartman88
ID: 24059119
I am using the formula to set a wingding character as a checkbox.  Chr(254) is a checkbox with a check and Chr(168) is an empty box.

The workaround I was trying to develop was based on the description below (for a boolean field rather than a string field):

Create a Formula with your column name and print Char(254) for true value and Char(168) for false value. Here is my formula look like:

If {Table.IsTeacher} = true then Chr(254) else Chr(168)

Now place the formula in your report designer and change font to Wingdings. You are all set.

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 101

Expert Comment

by:mlmcc
ID: 24060920
Try it this way

if {RComment1.C8}="0" then
    chr(254)
else
    chr(156)

mlmcc
0
 

Author Comment

by:Bartman88
ID: 24062457
mimcc - I tried your suggestion; however, I seem to get the same error - 'A number is required here'.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 24062610
Where are you using the formula?

You should just create a new formula with the code then drag it to the report.

mlmcc
0
 

Author Comment

by:Bartman88
ID: 24062783
I did and I am still getting the same error - a number is required.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 24063015
Can you copy and paste the formula here?

mlmcc
0
 

Author Comment

by:Bartman88
ID: 24063692
The formula applied is:

if {RComment1.C8}="0" then chr(254) else chr(156)

Could there be an issue with a null value not being evaluated correctly?
0
 
LVL 6

Expert Comment

by:agandau
ID: 24064405
Something like that could be the problem.  I think what mlmcc and James0628 were getting at earlier was that the problem is more in the {Rcomment1.C8} = "0" evaluation.  But then things were sidetracked with the "156" business.

Whether it's a null or an error from an implicit cast is hard to tell.  What is the datatype of the RComment1.C8 field, and is the formula containing the expression
       
       if {RComment1.C8}="0" then chr(254) else chr(156)

being used in another formula?
0
 

Author Comment

by:Bartman88
ID: 24064491
The RComment1.C8 field is a string datatype and this should be the only location where this equation is being used on the report.
0
 
LVL 6

Expert Comment

by:agandau
ID: 24064559
Then I don't think a null would process as an error, but would rather just cause the if statement to branch to the else clause.

But you said "should be the only location".  Are you sure it "is the only location"?  : )

If this Formula Field is called CheckBox, you're sure there isn't anything other than a report element containing @CheckBox?  If it's not that, I'll be darned I know.  Other than rebooting, of course (HAR! -- the default IT guy response.)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 24064859
Can you attach the report?

mlmcc
0
 

Author Comment

by:Bartman88
ID: 24065080
Apparently EE does not allow the uploading of *.rpt files and it will not accept these files even if they are in a zip file.  I have attached a screen capture of my report in the hopes that it might offer a clue as to where the problem might be.
Desktop.jpg
0
 

Author Comment

by:Bartman88
ID: 24065154
Here is an image of the error when I try to run the report.
Desktop2.jpg
0
 
LVL 6

Expert Comment

by:agandau
ID: 24065177
Is there formatting applied to the report element referencing @Formula1?
0
 
LVL 35

Expert Comment

by:James0628
ID: 24065460
I see you've been busy today.  :-)

 EE will let you attach a report, but it only accepts certain extensions, and RPT isn't one of them.  I'm pretty sure that it should accept a ZIP file containing a report.  I don't know why that didn't work for you.  But the simplest thing is just to change the extension on the report to one of the accepted types, like TXT.  You should be able to u/l that.  You might add a note saying that the extension needs to be changed back to RPT.

 Using something like Chr(254) would make a lot more sense than "254", so that part of your formula makes more sense now.

 As agandau pointed out, one of the things I was wondering was the data type of {RComment1.C8}.  If all that you're doing with this formula is using it as a field on the report, then the only way that I can think of that you could get that error is if {RComment1.C8} is numeric, not string.  Then again, if that were the case, CR would give you that error when you tried to save that formula.

 As was already suggested, maybe you're using the formula somewhere else, in a place where CR expects the result of the formula to be a number.  When you look at the list of formulas in the Field Explorer, that formula should have a check by it, indicating that it's being used.  If you remove that formula from the report, does the check go away?  If so, that is the only place that the formula was being used.  If not, it's also being used somewhere else in the report (eg. in another formula).

 James
0
 
LVL 35

Expert Comment

by:James0628
ID: 24065468
Another thing:

 If you right-click on "Database Fields" in the "Field Explorer", do you have the "Show Field Type" option?  If so, you might want to turn that on.  That's an easy way to see the field types (like for C8) at a glance.

 James
0
 

Author Comment

by:Bartman88
ID: 24065472
James0628 - thanks for the good idea.  Comment2-rpt-.txt should be converted to Comment2.rpt and Comment2-vb-.txt to Comment2.vb (if it is any help).
Comment2-rpt-.txt
Comment2-vb-.txt
0
 
LVL 35

Accepted Solution

by:
James0628 earned 2000 total points
ID: 24065535
OK, I've looked at the report.

 The error message that you posted earlier says that the error is on Formula1.  Formula1 is only used in one place, as a field on the report.  C8 is type string.

 I honestly don't see how you could be getting that error.

 About the only thing that I can think of at the moment is if the data type for C8 was somehow being changed (from string to numeric) when you ran the report.  I don't know if that's possible.  I just can't think of anything else to try at the moment.

 So, just for the heck of it, try changing the formula and taking the quotes off of the 0 (so you have =0 instead of ="0").  CR will probably tell you that there's an error in the formula.  Save it anyway.  Then try to run the report again.  If the data type is somehow being changed, maybe that will work.  Even if it doesn't work, it might be interesting to see what happens.  Do you still get the old error, or something different?

 James
0
 
LVL 35

Expert Comment

by:James0628
ID: 24065549
Oh.  Duh.  Thought of this just after I posted (of course :-).

 With the report open in CR, go to Database > "Verify Database".  That will have CR check the structure of your datasource.  It's possible that C8 has changed and is now numeric, but the report isn't aware of it.

 For some reason I actually kind of doubt that that's the problem, but it's definitely worth a try.

 James
0
 

Author Comment

by:Bartman88
ID: 24065581
It looks like the expression did not like the quotations around the zero.  Both syntax checks failed; however, it seems to run fine.  The working equation is:

if {RComment1.C8}=0 then chr(254) else chr(156)

Many thanks.
0
 
LVL 35

Expert Comment

by:James0628
ID: 24065635
Interesting.  I guess the data type is changing, or has changed, after all.  It didn't seem likely, but, like I said, I just couldn't think of anything else.

 Did you try the "verify database"?  If the type has changed and the report just doesn't know it yet, that should fix it (so the report knows that C8 is numeric, and CR won't give you an error when you edit the formula).

 OTOH, if the data type is somehow being reported as string when you edit the report, but changes to numeric when you run the report, this may just be something that you have to live with.


 FWIW, I think mlmcc deserves some credit for pointing out that you should be using Chr().

 James
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 24065916
James - EE checks zip files for "illegal" extensions so the only way is to change the file extension.  I have requested that RPT be added and it is in the pipeline just not sure how long the pipe is.

mlmcc
0
 
LVL 35

Expert Comment

by:James0628
ID: 24066887
Ah.  I didn't realize that.  I thought I'd seen RPT files u/l'ed in ZIP files before, but I guess not.  Thanks for the explanation/correction.

 James
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question