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!

if statements 1

Status
Not open for further replies.

mjmiller24

Programmer
Aug 29, 2001
17
0
0
US
Okay, I know that this is not that hard.

I am trying to implement the following piece of code in Crystal Syntax:


if ( Remainder(RecordNumber, 2) <> 0 ) then
&quot;SEE ATTACHED&quot;


The problem is that I keep getting an error message saying that the if statement has to return a boolean. What am I doing wrong, and how can I fix this?

I appreciate any help.
 
Probably it is returning False when the condition is not true
 
That is correct crystal syntax, if that is the complete code for the formula. You may be using this code in a Record Selection formula, which (in order to select records) MUST return a boolean, and therefore will trigger that type of error message. Otherwise, you may have other code following or preceding this snippet. To logically separate code, use a semicolon at the end of the statement.
You should also consider explicitly defining what your else condition is, as in
if ( Remainder(RecordNumber, 2) <> 0 ) then
&quot;SEE ATTACHED&quot;
else
&quot;&quot; ;
 
Hi,

Because the field you are testing is numeric, the formula expects the result of the formula to be numeric also !!

You need to use a variable...

local stringvar f_result := &quot;&quot;;
if ( Remainder(RecordNumber, 2) <> 0 ) then
f_result := &quot;SEE ATTACHED&quot;;
f_result


Hth,
Geoff
 
What sort of error message do you get with the original code, Geoff? It works OK for me as a formula.
 
Hello,

I forgot to send a reply to these messages yesterday. The last suggestion, from Geoff, worked great. Thank you all for your help!
 
Now I'm really curious. Neither the problem makes sense, nor does the solution. Maybe I should take up golf...
Am I the only one confused by this thread?
 
Hi Idle,

This is a common occurence when creating formula with CR7.

It's just something I do when I need to fix this particular error message when I had the same problem!!

Geoff

PS. Not sure why it happens but it does
 
Thanks for explanation, FoxG. I'll hold off on golf.
That is strange - does it only occur when you don't include an Else statement?
 
IDLE:

I have experienced the exact same problem WAY TOO MANY times! For some reason, Crystal always wants your return values to match the data type of the field you are testing. For example, if you have a field that contains integers, Crystal will give you that message if you say something like:

if FIELD > 1 then
&quot;Jon&quot;
elseif FIELD < 1 then
FIELDVALUE

What I usually do is like Geoff suggested, I just make a variable and set it in the formula, then I suppress that formula and make another formula that just prints the variable value. I'm sure there is an easier way, but that's what I always do and it seems to work.
 
Hi,

Why do you need the second formula?

Does the formula in the details not give the correct result.

Geoff
 
Well, I never experienced this error, and am not able to duplicate it. I guess that this is fixed in version 8 and later. I wonder if this might only occur if you write an if-then-else statement without a closing else. Can anyone with V7 duplicate this, and see if it only occurs when the else statement is missing? I'm curious... but not curious enough to reload version 7.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top