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

variable losing it's value from one section to the next

Status
Not open for further replies.

Davest11

Programmer
Oct 26, 2004
82
US
I've written a report in Crystal v8.5. I'm trying to conditionally add an additional page at the end of a group to facilitate duplex printing. I've created a formula that assigns a value to a shared boolean variable based on the value of the pagenumber:

shared booleanVar BlankEnd;
if remainder (pagenumber, 2) <> 0 then BlankEnd := true


The correct value is being assigned to the variable. In the next section, I'm conditionally adding a new page after, also when remainder (pagenumber, 2) <> 0. My problem is that, when I show the value of the variable in this next section, it's always <false>.

All that's happening here is the conditional page add; there are no other formulas being run between when the value of the variable is assigned and when I'm showing it.

Also, I created another section between the section where the value is applied to the variable and when the page is conditionally added, showed the variable there, and the assigned value shows correctly.

Any thoughts would be greatly appreciated.

-Dave
 
Another bit of information. Even when I remove the conditional page add from the following section, the variable value is cleared to <false> when the report goes to a new page on its own. Has anyone run into a situation where the value of a variable spontaineously changes when a report advances to a new page?
 
I would approach this differently. I would insert a second group footer section GF_b. Then in the section expert (format->section)->Group Footer (supracategory)->check "New Page After" and "Reset Page Number After". Then for Group Footer_b->New Page Before->x+2->enter:

remainder(pagenumber,2) = 1

-LB
 
Thanks for the input, LB. Actually, this is what I have done, as far as it goes, and the blank page is being added as it should be. My customer also wants me to print a field on the blank page stating "This page intentionally left blank", and this is what's causing me the problem. I have to have a way to conditionally suppress the section with this text field based on whether the last page is an intentionally blank page. Thus, I assigned it the value of true based on the same criteria that I use to add the blank page, remainder (pagenumber,2) <> 0 (or remainder (pagenumber,2) = 1). I could't come up with another way to tell Crystal whether or not the last page was an "intentionally blank" page or not.

Other than finding a solution to the immediate problem, though, I'm very curions if anyone has seen a similar situation - where a variable seemingly spontaineously looses its assigned value at a page break. I can see no reason for this to happen.

-Dave
 
I think you just need to place a text box in GF_b with the message, and then format it to suppress with:

remainder(pagenumber,2) = 0

I think the reason the variable is "losing its value" is that when you add a conditional page, you are changing an element of the formula itself--pagenumber.

-LB
 
The reason that I can't do that is that the report could actually end on an even-numbered page. In that case, I don't need to add an additional blank page, and I don't want to see the "blank page" message, because the last page won't be blank.

As far as the change of pagenumber causing the variable issue, that would make sense to me if I was actually re-running the formula after the pagenumber changed. The reason that I used a variable was so that I could assign its value when the condition actually existed (the report coming to an end when the pagenumber is odd). I'm then suppressing the "blank" section by looking at the value of the variable, not at the value of the formula.
 
I tested my suggestions above and they work for me. Did you try this approach? Let me reiterate (and expand a little):

1)Insert a second group footer section GF_b. Then in the section expert (format->section)->Group Footer (supracategory)->"New Page After" and add the following in
the x+2 formula area:

not onlastrecord

2) In the section expert (format->section)->Group Footer (supracategory)->check "Reset Page Number After".

3)Then for Group Footer_b->New Page Before->x+2->enter:

remainder(pagenumber,2) = 1

4)Place a text box in GF_b with the message, and then format it to suppress with:

remainder(pagenumber,2) = 0

If you want a page number that does not reset after each group, continue to use the "reset page number after" on the group footer, but create a formula for the page number:

whileprintingrecords;
numbervar pageno := pageno + 1

Place this in the pageheader instead of the special field pagenumber (but continue to use the reset page number on the group footer section formatting).

-LB
 
Thanks again for the input, but no, this approach won't work with my report. For one thing, if I put "reset page number" in the group footer supercatagory, it resets the page number after every section of the group footer, and I have 15 of them in this report, most containing a subreport that takes up one full page. If I move the "reset page after" to the last GF section (as I usually do), and follow all of your other suggestions (which is approximately where I started out yesterday, before trying to implement the variable), the blank page comes up as it should, but the "this page blank" text box never shows. This is because the suppression test is executed before the page number is advanced, while the pagenumber is still odd.

If anyone else out there is reading this, does anyone have any thoughts on the root questions that I'm asking here...why the value of a variable would be reset when the formula that populates it is not being re-run? Is there a way to prevent this from happening? Thanks!

-Dave

 
I started rereading your posts and decided that I'd refer you to simply summarize your thread as you reveal more info each time:

Report layout (show sections, groups, etc)
Where are the subreports
What formulas are used, and where
Expected result

-k
 
One more time. Here's a slightly different approach. Insert a final group footer section (let's call it group footer_x) that contains a text box with your message. In design mode, stretch the section so that it takes up a full page. Then go to the section expert->group footer_x->check both "New page before" and "New Page After". In the New Page After x+2 formula area also add:

Not Onlastrecord

Still in the section expert, highlight Group footer_x ->suppress->x+2 and enter:

remainder(pagenumber,2) <> 0

This should work even with multiple, lengthy group footer sections.

Regarding the changing value of your variable--although you are setting the variable to true, it is based on a condition--that the remainder of the pagenumber divided by 2 = 0. When the pagenumber changes, it will change the value of your variable. You don't really need a variable. The formula accomplishes the same thing.

-LB
 
I really appreciate all of your help on this, LB, and I will give your latest suggestion a try. I would like, though, to discuss the issue of the variable a bit further. Look at the Crystal report as a program. Early in my code, I set the value of x to equal the value of y + z, because I want to reference the value of y + z, at that point, later in the code. Ten lines down, the value of y changes. If I don't explicitly reset x, it will still contain the sum of z and the previous value of y, which is what I want. If I set a variable to equal the page number at a certain point in the report, that variable should (and does) hold its value throughout the report, even after the page number has advanced. This is fairly basic programming.

I've also experimented with putting the original formula that I was dealing with (setting the variable to True when a blank page at the end is required) in other sections of the report. When I place it in sections other than the one that I need it to be in, it works as it should. I know that this is very ambiguous - I'd be glad to send you files that illustrate this if it's unclear.

I think that I'm dealing with a bug here. Again, back to the question I originally asked - has anyone out there seen an instance where the values of variables in Crystal change spontaineously?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top