Solved

Trying to Display Checkbox on Crystal Report

Posted on 2009-04-02
25
1,163 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
  • 9
  • 8
  • 5
  • +1
25 Comments
 
LVL 34

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 34

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
 
LVL 100

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 100

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 100

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 100

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 34

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 34

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 34

Accepted Solution

by:
James0628 earned 500 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 34

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 34

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 100

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 34

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now