Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Incorrect results from AND

edited May 2009 in RAP
procedure Variable1OnCalc(var Value: Variant);
var
i,i1:integer;

begin
i := -1;
i1 := -1;
if (i = -1) and (i1 = -1) then
Value := -1
else
value := 0;
end;

I am creating a conplex (for me!) end user report using ReportBuilder V7.04
and am finding odd results when testing for negative numbers using RAP.

The code above (Variable1OnCalc) produces a value of 0 when it should be -1.
If I only test 1 value (eg i = -1) then I get 0. If I change the syntax to
the following I also get a result of 0.
if (i = -1) then
if (i1 = -1) then
Value := -1
else
value := 0;

Is this a known problem? I am very concerned as this report has a lot of
ANDs in the calcs and I cannot be sure of getting the correct results.

I do have the latest version of ReportBuilder (I will test this later) but
I have to use 7.04 for this job.

Hope you can help

John

Comments

  • edited May 2009
    Hi John,

    This was not a known issue with RB 7.04. In my testing with the latest
    version of ReportBuilder, the RAP code you have below seems to work
    correctly. You might try working around the issue by using boolean
    variables. For your workaround attempt, you might try placing everything in
    a begin...end and see if that helps.

    lbi := (i=-1);
    lbi1 := (i1=-1);

    if (lbi) and (lbi1) then
    Value =...

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2009
    To echo Nico, it works for me using RB 11.04.

    Perhaps the issue is not the 'and' operator, but more likely the negation
    uniary operator "-". Since the "-" operator can representative negation or
    subtraction it is a bit tricky. Or perhaps it is combination of using the
    "and" operator with the "-" operator.

    You could try putting the -1 into a constant value and then comparing the
    two.

    const
    cNegativeOne = -1;

    begin

    if (i = -cNegativeOne ) and (i1 = cNegativeOne) then


    end;


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited February 2010
    Hi All,

    We are running with Report Builder 11.03 Enterprise and we have experienced
    a similar issue, we also clicked onto the idea of using nested if statements
    to circumvent this problem:

    var iNormalised : double; begin iNormalised := 0; TheShape.brush.color := clWhite; iNormalised := (iScore / iUsers); {THIS WORKS} If (iNormalised <= -0.6) then TheShape.brush.color := rgb(255,0,0) else If (iNormalised <= -0.2) then TheShape.brush.color := rgb(255,165,0) else if (iNormalised <= 0.2) then TheShape.brush.color := rgb(255,255,0) else if (iNormalised <= 0.6) then TheShape.brush.color := rgb(154,205,50) else if (iNormalised <= 1) then TheShape.brush.color := rgb(100,149,237); {WHY DOES THE THIS NOT WORK? If iNormalised = -1, the top 2 lines evaluate as true} { If (iNormalised >= -1) And (iNormalised <= -0.6) then TheShape.brush.color := rgb(255,0,0); If (iNormalised > -0.6) And (iNormalised <= -0.2) then TheShape.brush.color := rgb(255,165,0); if (iNormalised > -0.2) And (iNormalised <= 0.2) Then TheShape.brush.color := rgb(255,255,0); if (iNormalised > 0.2) And (iNormalised <=0.6) then TheShape.brush.color := rgb(154,205,50); if (iNormalised > 0.6) And (iNormalised <= 1) then TheShape.brush.color := rgb(100,149,237); } end;

    I have found in the second block of code (which is not working) that if i
    reversed the lines so that it would evaluate
    the positive lines first and work it's way down towards the negative lines
    then it would work correctly.

    Is this an issue with ReportBuilder? We are concerned because then we may
    need to revisit a large number of reports and need to know.

    Regards,

    Anton Bosch


  • edited February 2010
    Hi Anton,

    In my quick testing I'm unable to recreate this behavior in RAP. If
    possible, please send a simple example that I can run on my machine in .zip
    format to support@digital-metaphors.com and I'll take a look at it for you.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2010
    Thanks for the reply Nico,

    I will first try this on the new version and get back to you.

    Anton

This discussion has been closed.