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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF...THEN...ELSE error 1

Status
Not open for further replies.

BobLucas

MIS
Feb 13, 2009
7
US
I'm using the following code in a formula variable (Crystal 11.0.0). On the first version, the error checker highlights the Else clause and says "A number is needed here." I broke the IF...THEN...ELSE into two IF statements and it works perfectly. I would appreciate any suggestions as to why this is necessary.

VERSION 1:

Local NumberVar tLen := length({?Test Method});
Local NumberVar start := 1;
Local NumberVar i := 1;
Local StringVar str := '';
//Loop through {GILEAD_TEST_METHODS.TEXT9} inserting HTML formatting around search string
While i>0 Do
(
i := instr(start,{GILEAD_TEST_METHODS.TEXT9},{?Test Method},1); //Case-insensitive search
If i > 0 Then (
str := str & mid({GILEAD_TEST_METHODS.TEXT9},start,i-start)&
'<b><font color="Red">' & Uppercase({?Test Method}) &'</font></b>';
start := i+tLen;
)
Else
str := str & mid({GILEAD_TEST_METHODS.TEXT9},start)
);
//Return the HTML-formatted string
str

VERSION 2:

Local NumberVar tLen := length({?Test Method});
Local NumberVar start := 1;
Local NumberVar i := 1;
Local StringVar str := '';
//Loop through {GILEAD_TEST_METHODS.TEXT9} inserting HTML formatting around search string
While i>0 Do
(
i := instr(start,{GILEAD_TEST_METHODS.TEXT9},{?Test Method},1); //Case-insensitive search
If i > 0 Then (
str := str & mid({GILEAD_TEST_METHODS.TEXT9},start,i-start)&
'<b><font color="Red">' & Uppercase({?Test Method}) &'</font></b>';
start := i+tLen;);
//Else
If i = 0 Then
str := str & mid({GILEAD_TEST_METHODS.TEXT9},start);
);
//Return the HTML-formatted string
str




 
Hi,
Not sure, but since you are returning both a number and a string in the first version ( If i>0 ) then the Else clause must also return a Number - If..Then..else formulas (and other CR formulas) must use the same type ( Number, string,boolean, etc) throughout.

[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Changing the Else clause to
Else (
str := str & mid({GILEAD_TEST_METHODS.TEXT9},start);
start := 1;) //Crystal requires a parallel construction

worked. Thanks.
 
Hi,
Glad to help..been there , done that...






[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top