Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting text from a string field

Status
Not open for further replies.

dbltt25

MIS
Nov 29, 2000
28
0
0
US
IF anyone could help me try to trouble my formula below, I would greatly appreciate it:

If trim({cpfind.RECNO}) = "2" then "Pregant Woman"
else if trim({cpfind.RECNO}) = "3" then "Breastfeeding Woman"
else if trim({cpfind.RECNO}) = "4" then "Postpartum Woman"
else "bogus"

This is the formula that I am trying to use to set my text. The cpfind.recno is a string field that holds 10 characters. I know that I have all 3 set in my database and I continue to get the bogus message.

Any help, I would appreciate it!!
Thanks

 
Hi,
Have you tried the tonumber(x) command and just check the number? You could also try if = "2 " and see if that works first. I hope this helps!
Brett
 
So, is it not picking up any of the numbers? All of the results are "bogus"? One thing you can try is using single quotes ('2','3' e.g.). I think the tonumber(x) suggestions is a good one too.

Kathryn
 
The formula is not picking up any of the numbers. All I continue to get is the bogus message. I have tried the tonumber and single quotes options. I have also tried using the VAL function. Thanks for your help, any more suggestions?? Thanks again!!
 
Well, it seems pretty strange. One thing you can try which may help you debug this is to set up some new formulas. One which is just trim({cpfind.RECNO}) and one that is tonumber({cpfind.RECNO}). Place these formulas on the report near the original formula and see what shows up.

Also, just as a stretch, try reducing the formula to just one if then statement

if trim({cpfind.RECNO}) = "4"
then "Postpartum Woman"
else "bogus"

One other thing, just to be sure, when you change your compare to use the val and tonumber functions, make sure the compared value isn't in quotes, but is numeric. You probably know this, but since I didn't see your other code, I wasn't sure.

What a frustrating problem.
X-)
Kathryn
 
First I would put the code in a case statement...

select tonumber({cpfind.RECNO})
case 2:
"Pregnant Woman"
case 3:
"Breastfeeding Woman"
case 4:
"Postpartum Woman"
default:
"bogus = " & tonumber({cpfind.RECNO})

Now run it. When the code gets to default, it will also print out the value of RECNO. I can get a better understanding of what is happening from that...
Brett Please visit my websites!
 
I am fairly new to crystal, but maybe someone can explain this to me. I am trying to run this formula from the page header in the layout of my report. However, when I place this formula in the details portion, it runs fine. Of course, I have to suppress if duplicate. However, I don't want to run this formula on every record in my database. Plus this is one formula out of about 20 that I have to do for this report. I was thinking that I could most of my report on the page header and page footer.

Any thoughts or idea's as to why this formula works fine in the details portion, but not in the page header??

Thanks again for all the help!!
 
Are you using a formula field? If you are not, put the formula in a formula field and then put the formula field in your title. That is how I am currently doing it.
Brett

P.S. If you are using a formula field, explain to me how you are doing it, or show me the code... Please visit my websites!
 
Yes, I have inserted a formula field into the page header.

This is the code that I am using currently:

If val({cpfind.RECNO}) = 2 then "Pregnant Woman"
else if val({cpfind.RECNO}) = 3 then "Breastfeeding Woman"
else if val({cpfind.RECNO}) = 4 then "Postpartum Woman"
else ""

If I do place this in the details section, it prints out on the second page, because of the record (Pregnant woman is #2) in the database. I am not sure what you mean by placing the formula into the title.

I really appreciate your help.
Thanks!!
 
On your database fields window. This is where you can drag and drop your fields to your report. You can set up "formula fields." They are referenced by using an "@" symbol before the name. You add the formula into the formula field. Then you "edit text object" in the header/footer and drag and drop the formula field into the text object. Your text object might look like this:

Type of woman: @WomanType

(@WomanType would be in brackets after you drop it).

If you need more help, e-mail me directly @
brett_burnell@email.com
Brett Please visit my websites!
 
dbltt25,
Heres how i understand Crystal Reports processing. First the report and page headers are evaluated, including any formulas contained in these sections. At this point no data has been read. Then the body of the report is evaluated, this includes group headers and footers and the details section(You can think of these sections as nested loops, one iteration of the detail 'loop' for each record. The group header and footer 'loops' get one iteration each time you see that group header or footer on the final report). Then the report footer is evaluated. This may not be 100% correct, but the concepts are right. So your woman type formula is being evaluated before the database is ever accessed, of course you're not getting the correct result. If each details section represents a woman's record in the database why wouldn't you want the formula in the details section? anyway, the header is definitely not going to work.
Ruairi
ruairi@logsoftware.com
Experienced with:

VB6, SQL Server, QBASIC, C(unix), MS Office VBA solutions

ALSO: Machine Control/Automation using GE and Omron PLC's and HMI(human machine interface) for industrial applications
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top