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

type of variable as a result of a result of a control structure 1

Status
Not open for further replies.

DvDvDvDv

Programmer
May 24, 2001
100
PT
Hi all.

This is a simple question and probably easy to answer me, but I can't find out the solution.

I noted that when I use a control structure (as if then else, for instance), the result has to be in the same type of variable of the result of the else, so how can I change it ?

My problem is: in the following formula, I want to have a result as the percentage y of x, but if x = 0 I want a string as the result of the formula.


Example:

if x <> 0 then
y % x
else
&quot;n. a.&quot;

But it doesn't works, because if the first result is a number, Crystal asks for a same type variable in the else part of the control structure.

Anyone can answer me ?

Thanks for helping

Dv
 
You are right. The answer is to have both be text.

if x <> 0
then ToText (y % x)
else &quot;n. a.&quot;


Another option is to have 2 different fields, one on top of the other, and suppress them based on opposite conditions. Ken Hamady
On-site custom Crystal Reports Training and Consulting.
Quick Reference Guide to using Crystal in VB.
 
Now I created another problem:

How I can format the number before it becomes a string in the same formula ?

Example:

if x <> 0
then (ToText (y % x) + &quot; % &quot;)
else &quot;n. a.&quot;

The result, for instance, is 69,45 %. But I want the result as 69 %. How can I format a number inside a formula without creating another formula ?

The way I now is using the instr and detecting where the . is, but maybe there is a better solution.

Dv
 
Totext has formatting options:

Totext({field} , 0 ) should work. Ken Hamady
On-site custom Crystal Reports Training and Consulting.
Quick Reference Guide to using Crystal in VB.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top