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

If then statement

Status
Not open for further replies.

rmarcus

IS-IT--Management
Feb 18, 2001
15
ZA
I have a formula which has a number of If then conditions. If a particular condition exist, I want the report to print a blank space. Can I do this in V7 ?

I have tried using "" but it says a number is required.

Thanks

Ralph
 
All the return values of your if..then's must return the same data type. As Brian suggested, posting the formula will help you get the best answer. Otherwise you might get a suggestion that doesn't fit your needs.
 
Sorry, here is the formula ..

If ({crItemTRX.UOFM} = "BOX OF 2") then {crItemTRX.QTY}*2
else If ({crItemTRX.UOFM} = "BOX OF 5") then {crItemTRX.QTY}*5
else If ({crItemTRX.UOFM} = "BOX OF 3") then {crItemTRX.QTY}*3
else If ({crItemTRX.UOFM} = "BX OF 10") then {crItemTRX.QTY}*10
else If ({crItemTRX.UOFM} = "BX OF 12") then {crItemTRX.QTY}*12
else If ({crItemTRX.UOFM} = "BX OF 20") then {crItemTRX.QTY}*20
else If ({crItemTRX.UOFM} = "BX OF 24") then {crItemTRX.QTY}*24
else If ({crItemTRX.UOFM} = "BX OF 25") then {crItemTRX.QTY}*25
else If ({crItemTRX.UOFM} = "BX OF 50") then {crItemTRX.QTY}*50
else If ({crItemTRX.UOFM} = "BX OF 6") then {crItemTRX.QTY}*6
else If ({crItemTRX.UOFM} = "DOZEN") then {crItemTRX.QTY}*12
else ""

 
So, your problem is that all your conditions return a value, but the last else is returning a string. Crystal does not allow this.

You could do a couple of things to address this. Change the last else statement to read:

else 0

Then format the formula to suppress zeros. That seems the most straightforward.

You could also do the following: Modify the existing formula to use the ToText function, as in:

If ({crItemTRX.UOFM} = "BOX OF 2") then ToText({crItemTRX.QTY}*2,0)

This would cause all return values to be strings. If you want to show decimal places, change the ",0)" at the end of the function to be whatever number of decimal places you want (e.g. ToText({crItemTRX.QTY}*2,2) would show 2 decimal places). The downside is that you would not be able to use this formula (easily, at least) in other summaries/formulas. So, if you need to summarize the numbers, you would actually need your original formula, modified to return 0 for the last statement, placed on the report, but most likely suppressed (and use that formula for the summaries and other formulas) and then the formula that just returns strings placed on the report for display purposes.


 
rmarcus,

Here is the easiest way:

Select ({crItemTRX.UOFM}
case "BOX OF 2": {crItemTRX.QTY}*2
case "BOX OF 5": {crItemTRX.QTY}*5
case "BOX OF 3": then {crItemTRX.QTY}*3
case "BX OF 10": {crItemTRX.QTY}*10
case "BX OF 12": {crItemTRX.QTY}*12
case "BX OF 20":{crItemTRX.QTY}*20
case "BX OF 24":{crItemTRX.QTY}*24
case "BX OF 25": {crItemTRX.QTY}*25
case "BX OF 50":{crItemTRX.QTY}*50
case "BX OF 6":{crItemTRX.QTY}*6
case "DOZEN":{crItemTRX.QTY}*12
default : 0;

Then format the formula to be suppressed if @formula = 0

I hope this simplifys things a little more for you!

Cheers,

paulmarr
 
Thanks for you help and prompt responses. My problem is solved !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top