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!

Crystal Reports 7 Syntax Error - Can you find it? 2

Status
Not open for further replies.

JonAtBits

Programmer
Apr 11, 2005
3
ZA
Hi list,

I cannot understand why this causes a syntax error. I get a 'Remaining text does not appear to be a part of the formula' error for the innermost nested 'else' in the code. The code follows:

----code snippet of ERROR code------------


//Calculate the difference between the Sell Price and the KeyPak Price
//and the Commision amount now.
Global numberVar KPSPDifference := {ado.sellprice} - {ado.price/unit};
Global numberVar KPCommAmount := {ado.price/unit} * (10/100);
Global numberVar KPCommission := 0;
Global numberVar KPCommissionShared := 0;

//If we have a regular record then simply pass through the commission value from SQL
if {ado.Type} = 0 Then
//Extract commission from sql
{ado.comm}

//If we have a Manual Invoice type then calculate the commission
else
//If the selling price is larger than the unit price
if {ado.sellprice} > {ado.price/unit} then

//If the difference is greater than or equal to 10% of the unit price.
if KPSPDifference >= KPCommAmount then
KPCommission := KPCommission + KPCommAmount;

//If the Difference is greater than the Commission amount then calculate the split commission
if KPSPDifference > KPCommAmount then
KPCommissionShared := KPSPDifference - KPCommAmount;
KPCommission := KPCommission + KPCommissionShared;

//Return the calculated commission value incl. the commission split
KPCommission
else
//Return the calculated commission value incl. the commission split
KPCommission

else
//Else commission is the difference between the cost and selling price.
KPCommission := KPCommission + KPSPDifference;
KPCommission
else
//Selling price is less than KeyPak price
//so there can be no commission. Commission is 0.
0


----code snippet of ERROR code------------


Can anyone offfer advice?

The previous code (before I tried to complete it was fine uo to the following point (see OK code below this text):

----code snippet of OK code-----------

//Calculate the difference between the Sell Price and the KeyPak Price
//and the Commision amount now.
Global numberVar KPSPDifference := {ado.sellprice} - {ado.price/unit};
Global numberVar KPCommAmount := {ado.price/unit} * (10/100);
Global numberVar KPCommission := 0;
Global numberVar KPCommissionShared := 0;

//If we have a regular record then simply pass through the commission value from SQL
if {ado.Type} = 0 Then
//Extract commission from sql
{ado.comm}

//If we have a Manual Invoice type then calculate the commission
else
//If the selling price is larger than the unit price
if {ado.sellprice} > {ado.price/unit} then

//If the difference is greater than or equal to 10% of the unit price.
if KPSPDifference >= KPCommAmount then
KPCommission := KPCommission + KPCommAmount




else
//Else commission is the difference between the cost and selling price.
KPCommission := KPCommission + KPSPDifference
else
//Selling price is less than KeyPak price
//so there can be no commission. Commission is 0.
0

----code snippet of OK code-----------

Can anyone offer advice?

Regards and Thanks

JonAtBits
 
Jon,
the only bit that I could see as perhaps being the cause was:

Code:
 //If the Difference is greater than the Commission amount then calculate the split commission
            if KPSPDifference > KPCommAmount then
                KPCommissionShared := KPSPDifference - KPCommAmount;
[b]                KPCommission := KPCommission + KPCommissionShared;

                //Return the calculated commission value incl. the commission split
                KPCommission [/b]
            else
                //Return the calculated commission value incl. the commission split
                KPCommission

The bit in bold doesn't have any matching IF condition. If you would like there to be multiple actions then it will be worth placing them in brackets. E.G:
Code:
if myfield=value
then (field2:=1; field3:=7;)
else ....

Hope this helps.
ShortyA
 
I would also try adding parens around the nested if-thens.

-LB
 
Thanks to all the valuable feedback from this list. Crystal 7 really is outdated ;). I finally managed to get the formula working using the hints and tips posted here. Here is the working formula.

------code OK snippet----------------------

if {ado.Type} = 0 then {ado.comm} else

( if {ado.Type} = 1 then if {ado.sellprice} < {ado.price/unit} Then 0 else

Global numberVar KPSPDifference := {ado.sellprice} - {ado.price/unit};
Global numberVar KPCommAmount := {ado.price/unit} * (10/100);
Global numberVar KPCommission := 0;
Global numberVar KPCommissionShared := 0;

if KPSPDifference >= KPCommAmount then (KPCommission := KPCommission + KPCommAmount) else (KPCommission := KPCommission + KPSPDifference; KPCommission);
if KPSPDifference > KPCommAmount then (KPCommissionShared := ((KPSPDifference - KPCommAmount)/2); KPCommission := KPCommission + KPCommissionShared; KPCommission) else KPCommission; )

------code OK snippet----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top