Solved

# Crystal Reports - If left 4 equal then print text

Posted on 2013-05-14
693 Views
Hi,

I see that there is a string function in Crystal Reports that allows me to replace a string is follows:

a:=replace(a,"EAN", "NEW");

I want to say, If the first four character in a string equals "SAMP" then replace with "NEWSAMP".

How do it do this in Crystal Reports?
0
Question by:Annette Wilson, MSIS
[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
• 5
• 4

LVL 101

Expert Comment

ID: 39165921
StringVar a;
If Left({a,4) = "SAMP" then
a := "NEW" & a;

mlmcc
0

Author Comment

ID: 39165981
mlmcc,

Thank you for responding.  In your solution, where is the field value evaluated?

If Left 4 of {FIELD} = "SAMP" then string = "NEW"
0

LVL 101

Expert Comment

ID: 39165996
Is a a variabloe or a field?

If it is a field you can't change field values.

mlmcc
0

Author Comment

ID: 39166551
Can I have a function that reads the first 4 characters in the field and when and display text according to the first 4 characters.

I'm not trying to change field values, just make sure the when a field has a certain first 4 characters that the report displays text.

I am able to do this in other reporting programs with a StringIF function.

Is there a StringIF in Crystal Reports?
0

LVL 101

Expert Comment

ID: 39166658
There is no stringIf.

You can use

If Left({YourFIeld},4) = "SAMP" then
"NEW"
Else if Left({YourFIeld},4) = "STAN" then
"OLD"
etc

mlmcc
0

Accepted Solution

Annette Wilson, MSIS earned 0 total points
ID: 39229286
I tried the following and nothing comes up.

If Left({Field},4)="RNDT" then "RUN CONTROLLED"
Else if Left({Field},3)="TAC" then "TACT CONTROLLED"

Should I declare text as a string then evaluate?  If so, how would I write this in crystal reports?
0

LVL 101

Expert Comment

ID: 39229942
Try this

If UpperCase(Left({Field},4)) = "RNDT" then
"RUN CONTROLLED"
Else if UpperCase(Left({Field},3)) = "TAC" then
"TACT CONTROLLED"
Else
{Field}

mlmcc
0

LVL 101

Expert Comment

ID: 39230448
Did you need the formula?

mlmcc
0

Author Closing Comment

ID: 39240444
Thank you very much.  This worked.  I traced the data in the database and the data was never populated.  Once I took care of the correct query,  everything worked just fine.
0

## Featured Post

Question has a verified solution.

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

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â€¦
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you sâ€¦
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.â€¦
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as formâ€¦
###### Suggested Courses
Course of the Month2 days, 9 hours left to enroll