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

Calculating a label value in the detail band

edited August 2003 in General
Hi,

in the detail band i have a label which holds the values of three fields
from the database (they are obviously converted to string and concatenated
together). Is it possible to calulate the value of the label only once
(let's say at the report's first pass) and not every time the label is
displayed? I'm asking this because in the label's OnPrint event i have an
sql query which executes (to get the three values) and it's a little time
consuming. On the other hand, if i don't execute it every time the label is
displayed, the label has the same value across the whole report (i had a
similar problem in a previous post i made, and i used a TppVariable which
executed at every traversal...not very optimal).

Thanx for any suggestions

Comments

  • edited August 2003
    Hi jure,

    In the Report.OnStartPage, you could check to see if Report.FirstPass is
    true and if it is, make your calculations. This is definitely a good way to
    optimize what your report is printing.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003

    to

    Hi Nico,

    so you are saying that there is no need to refresh the label each time it's
    displayed. If i do so, the label has the same caption across the whole
    report (probbably the value of the last record that was printed).

    Or did you mean something else in your comment and i didn't understand
    right?
  • edited August 2003
    I'm sorry, I forgot to say to also check that the Report.AbsolutePageNo = 1,
    so that it will only fire once and you will have no repeats.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2003

    1,

    Sorry, but i think we misunderstod. You say that it's possible to
    print/calculate the labels only during the report's first pass. Then the
    user can navigate through pages and there is no need to refresh the label
    when it's printed again, if i understood well. But, as i said, if i don't
    refresh the label each time it prints (in the label's OnPrint event) the
    label has the same value in the whole report. Example:

    Correctly displayed report:

    ID ProblematicLabel
    1 A
    2 B
    3 C
    4 D
    5 E


    Erroneously displayed report:

    ID ProblematicLabel
    1 E
    2 E
    3 E
    4 E
    5 E

    If i wasn't clear enough, please tell me.

    Thanx
  • edited August 2003
    Hi,

    Ok, I think I understand what is going on. Since the TppLabel.OnPrint event
    fires numerous times during generation, you will need to keep track of the
    current ID (which you already have) and the previous ID (from the last time
    you entered this event). Each time you enter this event, check to see if
    the two values are the same. If they are not, update the previous ID to the
    current one and update the TppLabel component. If they are the same, do
    nothing and keep generating. This should get you going in the right
    direction.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.