×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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
"n. a."

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

RE: type of variable as a result of a result of a control structure

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

if x <> 0
then ToText (y % x)
else "n. a."


Another option is to have 2 different fields, one on top of the other, and suppress them based on opposite conditions.

Ken Hamady
http://www.kenhamady.com/
On-site custom Crystal Reports Training and Consulting.
Quick Reference Guide to using Crystal in VB.

RE: type of variable as a result of a result of a control structure

(OP)
Thanks Ken.

That's the best way.



Dv

RE: type of variable as a result of a result of a control structure

(OP)
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) + " % ")
else "n. a."

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

RE: type of variable as a result of a result of a control structure

Totext has formatting options:

Totext({field} , 0 )  should work.

Ken Hamady
http://www.kenhamady.com/
On-site custom Crystal Reports Training and Consulting.
Quick Reference Guide to using Crystal in VB.

RE: type of variable as a result of a result of a control structure

(OP)
It works !

Thanks again !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close