Avatar of Brent
BrentFlag for United States of America asked on

Error in If Statement with Boolean values in Crystal Report -

Hello,

I received help with my if statement in Crystal Reports:

https://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_28227399.html

I am trying to display my check boxes in a Crystal Report.

If {table.IsHospital} = true then
     formula = Chr(254) 
Else
      formula = Chr (168)
End if

Open in new window


I am not certain if I need to declare my field as a Boolean value, or is that automatic in Crystal because of the field properties?

I am getting error when I test the formulas:

=true    produces: must be a number
=1        produces: needs to be a Boolean Value
=Yes     Produces: must be a number

I believe my datatype field is logical

list in tables as:   (udtlogical(bit),null)

Thanks for any help.

Brent
Crystal Reports

Avatar of undefined
Last Comment
James0628

8/22/2022 - Mon
Mike McCracken

What does Crystal show the field as?

mlmcc
ASKER
Brent

When I check the format field, it is asking me for Boolean Text and it is set to Yes / No

I'll try to figure out how to exactly tell what field it sees it as.

thanks
ASKER
Brent

Yes, when I hoover over the fields in my Crystal Report, it shows (Boolean) after the field name.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
James0628

I don't use Basic syntax, but if the field is logical, the formula seems OK to me, and a similar formula passes a Basic syntax check here.

 You could try leaving out the test.  {table.IsHospital} by itself is the logical equivalent of ({table.IsHospital} = true).


If {table.IsHospital} then
     formula = Chr(254)
Else
      formula = Chr (168)
End if


 James
ASKER
Brent

James,

I just ran your modified formula with Crystal Syntax are received the following error:

It highlights formula=

and says: a number, currency amount, Boolean, date, date=time or string is expected here

Thanks
ASKER
Brent

I found in the help section what I suspected is that one of the formats is not correct. It's trying to compare apples to apples, but that's not what I have. I will have to go back to square one and figure out which data type is incorrect.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Mike McCracken

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Brent

Either way, I keep getting basically the same error, which is the data type is not matching up. I can see my data fields are Boolean, but not sure why Crystal doesn't recognize it. I am sure I am doing something incorrect, but it just might take a little more reading to figure it out.

I probably should pull the question until after the long holiday, but not sure how to handle it.

Thanks for looking at this and I'll check back as soon as I can figure some additional details.

Brent
James0628

The formula in your first post is Basic syntax, so I used the same thing.  Did you try that formula with CR set to use Basic syntax?  You can't really get an error about the data types not matching with that formula, because it's not comparing the field to anything.  It's just testing the field itself to see if it is True or False.

 James
ASKER
Brent

James,

I thought I had tried using both ways and still received an error, but I will double check first chance I get back at work
This might not make any sense but, "What if it is testing the field for true or false, but the field isn't true or false? Maybe Null or possibly a a different value like a number or text? I see the values, so that is not the case, just trying to understand. Thanks.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mike McCracken

Canyou upload the rpt file?

mlmcc
ASKER
Brent

Yes, I can tomorrow. I'll go by the office first chance I get.

Thanks.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Brent

Good morning,

Here is the CR report I am trying to figure out. I did not create it, but I am trying to figure it out while my boss in on vacation. He normally works with CR, but I am just starting to learn.  I understand VB, but not much about Crystal syntax.

Thanks for all the help.
Brent
S-Advanced-EMS-STEMI-Report.rpt
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Mike McCracken

Change to use Basic Syntax and it works just fine

mlmcc
ASKER
Brent

That's weird, when I try it at work, I get an error code. Can you upload the report as you have it working, then I can take that report to work and test it. I'm not familiar enough with Crystal to know if there are settings on my work machine, that I need to adjust.

Thanks! I'll test it tomorrow and post back.
Mike McCracken

There are no settings to adjust that I know of that affect formulas

mlmcc
S-Advanced-EMS-STEMI-Report-1-.rpt
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
Brent

Thanks. I'll look at it tomorrow, then award the points.
ASKER
Brent

I think I might have figured out my problem. I went to work for a little bit and I notice something I did not see before. When I look at your CR, I see that you have a different "Box" (not sure what it is called maybe field?) for your formula check. On the attached screen shot the formula field you created shows wingdings (I changed to display the CHR correctly). I was attempting to put my formula into the YES box (field) right next to the EKG Transmitted: Yes

Does my formula go into a new field all by itself? or would it go into the Yes area.

I hope this makes sense, because I am not doing well with the terminology yet.

When I ran your formula at work, I did not get the error. I copied into my "Yes" box and I get an error. That might be my problem, I am putting the formula in the wrong area.

I'll do some reading.

*** After some reading, I wonder if what I want to do is Conditional Formatting?

Thanks! Brent
example-for-field.JPG
aikimark

@bvanscoy678

Are you driving this from a VB6 or VB.Net application?

aikimark -- zone advisor
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Mike McCracken

The formula is in the report.  It is not affected by the application calling the report

mlmcc
ASKER
Brent

James,

I missed your earlier comment about nulls. In the record I am testing, there is a value. But, your point is well made and I'll look at the default values tomorrow. I know that Nulls are allowed as part of the table properties, so it will be something I'll need to address once I get it working. The more I read, the more I understand it. This is my first interaction with Crystal and formulas, so I feel a bit out of place. Both answers for the  formulas are correct, so I will award point tomorrow. I just want to finish the thread for future queries on the subject.

Thank you both for your patience and help. Brent
ASKER
Brent

After I loaded the formula into the original report, it works just fine!

Thanks for all the help and I'll post points.

Thanks,
Brent
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
Brent

Thanks for the help guys!

Brent
James0628

You're welcome.  I'm glad you were finally able to get it working.

 James