x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 628

# Crystal Report 2011 - String Concatenation

Hello Experts
I am trying to write the below in the formula field but looks like its not accepting all the below as one string may be due to the IF statement? Please can someone advice how can I go about fix this?

Thanks

``````NumberVar d := CDbl({Lde.Day});
StringVar s := "This deed of entitlement is  made the ";
s := s & " " ;
If d >= 4 And d <= 20 Then
s := s & " " &   ToText(d, 0, "") & "th" ;
Else If d = 1 Then
s := s & " " &  "1st";
Else If d = 2 then
s := s & " " &   "2nd";
Else If d = 3 then
s := s & " " &  "3rd";
Else If d >= 24 and d <= 30 Then
s := s & " " & ToText(d, 0, "") & "th";
Else If d = 21 Then
s := s & " " & "21st";
Else If d = 22 Then
s := s & " " & "22nd";
Else If d = 23 Then
s := s & " " & "23rd";
Else If d = 31 Then
s := s & " " & "31st";

s := s & " day of " & MonthName(CDbl({Laird.Month}));

s := s  & " in the year " & {Lde.Year};

s;
``````

This to appear in one line as below

``````This deed of entitlement is  made the                        day of                           in the year
``````
0
meinIT
• 2
• 2
2 Solutions

Commented:
Try adding WhilePrintingRecords; as the first line of the formula.

mlmcc
0

Author Commented:
Hi mlmcc
Thanks for your picking this up for me. I have added the statement in the first line but its still giving me this error. Please see attached.
untitled.PNG
0

Commented:
You need to remove the ";" before each Else.  A ";" is put at the end of a statement, and your if-else-if-else is one statement.  You need a ";" before the first If, and at the end of the last If (after "31st").

FWIW, I would use Select-Case instead of the if-else-if-else.  I just find that easier to follow when you have multiple tests like this.  But that's just a personal preference.

James
0

Commented:
Good catch James.  I didn't notice them and since he seemed to indicate the formula was working (not reporting an error), I didn't look too closely at the code since it seemed to be correct for what he wanted.

As written it should produce an error when saved.

mlmcc
0

Author Commented:
Thank you both for your help! Apologies for the delay in getting back to you on this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.