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

Weird IF error, not catching If statement.

Status
Not open for further replies.

redeemasp

Programmer
Jun 1, 2004
63
GB
Hi there

I've this weird IF error that isn't catching any of my IF statement, but running the last statement.

code:

If Left(GroupName ({Command.RRE_Code}),1) = "A"
// Business Services
then
shared stringvar shdvarACode = 'A';
shared currencyvar shdvarASellingPrice := Sum ({@Selling Price}, {Command.RRE_Code});
shared currencyvar shdvarANetSellingPrice := Sum ({@Selling Discount}, {Command.RRE_Code});
shared stringvar shdvarAdept := "Business Services";

If Left(GroupName ({Command.RRE_Code}),1) = "D"
// Consumer, Trade & Retail
then
shared stringvar shdvarDCode = 'D';
shared currencyvar shdvarDSellingPrice := Sum ({@Selling Price}, {Command.RRE_Code});
shared currencyvar shdvarDNetSellingPrice := Sum ({@Selling Discount}, {Command.RRE_Code});
shared stringvar shdvarDdept := "Consumer, Trade & Retail";

If Left(GroupName ({Command.RRE_Code}),1) = "E"
// IT/Telecoms
then
shared stringvar shdvarECode = 'E';
shared currencyvar shdvarESellingPrice := Sum ({@Selling Price}, {Command.RRE_Code});
shared currencyvar shdvarENetSellingPrice := Sum ({@Selling Discount}, {Command.RRE_Code});
shared stringvar shdvarEdept := "IT/Telecoms";

It seems that it keeps defaulting to IT Telecoms.?!?

Isn't Crystal wonderful..lol
 
When performing multiple assignments within a single if statement, you should use (). For example:

If (condition) then
(assignment 1;
assignment 2;);

This shows that both assignments should be executed as a result of the condition. The way your formula works, the first assignment after the THEN is the only one that is conditional. You are always returning "IT Telecoms" because this is the last assignment statement and you have not designated a return value.
 
It may be because your last group of variables are for the "E" group.

Try changing it to an "If Then Else" instead of an "If Then ;"

Code:
If Left(GroupName ({Command.RRE_Code}),1) = "A" 
// Business Services
then 
    [b]([/b]shared stringvar shdvarACode = 'A';
    shared currencyvar shdvarASellingPrice := Sum ({@Selling Price}, {Command.RRE_Code}); 
    shared currencyvar shdvarANetSellingPrice := Sum ({@Selling Discount}, {Command.RRE_Code});
    shared stringvar shdvarAdept := "Business Services") [b])else[/b]

If Left(GroupName ({Command.RRE_Code}),1) = "D" 
// Consumer, Trade & Retail
then 
    [b]([/b]shared stringvar shdvarDCode = 'D';
    shared currencyvar shdvarDSellingPrice := Sum ({@Selling Price}, {Command.RRE_Code}); 
    shared currencyvar shdvarDNetSellingPrice := Sum ({@Selling Discount}, {Command.RRE_Code});
    shared stringvar shdvarDdept := "Consumer, Trade & Retail" [b])else[/b] 
the rest...

Where are you using the shared variables? Is this where the data is "defaulting to"? Are you using the correct variables in that location?


Mike
 
I think Mike is right about using the "else's". It looks like you are using Crystal syntax, so I also think you are forgetting the ":" in each clause where you are trying to set the shdvarDCode.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top