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

Problems with NumberVar variable

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Hello,

I have a report that prints identical information but is sorted very differently based on the final recipient. To avoid multiple reports, I have defined a variable named SortKey and set it based on the ReportOption parm the user enters. That part is working just fine.

I have multiple groups and depending on the ReportOption they may or may not need to print so I am using Formula suppression. This is also working OK.

The problem comes when I need to print subtotals. Say for ReportOption 1 I need to print a subtotal for Group4 but ignore the changes for Group3. Because every Group3 break will trigger a Group4 break, I am using Global Numbervars defined as follows:

In the Detail Line:

Global NumberVar AccumTotal;
If RecordNumber = 1 Then AccumTotal := 0;
AccumTotal := AccumTotal + FieldValue;

Group4 Conditional Suppression:

WhilePrintingRecords;
Previous(Group4FieldName) = Group4NameFieldName

In Group4 Header:

Global NumberVar AccumTotal;
Local NumberVar locAccumTotal;
locAccumTotal := AccumTotal; // Save value for printing
AccumTotal := 0; // Reset accumulator
locAccumTotal // Print accumulated total

The problem is that it always prints 0 in the Group4 header. I know AccumTotal is accumulating properly because I am printing it in the detail line for testing purposes and it keeps right on going and is not reset. This is true even though the Group4 header prints where I would expect it to.

I haven't had to do anything like this for a while. Am I missing something obvious here? Thanks!

Have a great day!

j2consulting@yahoo.com
 
this isn't 100% clear but as a comment....suppression of a group just suppresses the display....not calculation in a detail line...though this doesn't see to be your problem.

Personally there is no reason to define LocAccumTotal as a local variable it is just a temp field to retain a printed value and is constantly updated when the field is entered ...hence is unaffected by changes elsewhere if this is possible....ditto defining others as Global....the variables are Global by default.

Again I am not sure this is your problem though

***************
Group4 Conditional Suppression:

WhilePrintingRecords;
Previous(Group4FieldName) = Group4NameFieldName
***************

is this a typo....you talk about suppressing Group 3 but this is Group4

Since the initial setting of AccumTotal is undefined until you reach the detail line...the first printing of it in the Group 4 header is absolutely going to be 0...

I would change this formula in the detail section to

NumberVar AccumTotal;

AccumTotal := AccumTotal + FieldValue;

and put this formula in the Report header to initialize AccumTotal

//@init
WhilePrintingRecords;
NumberVar AccumTotal := 0;

I would also add WhilePrintingRecords to all your formulas to make sure they are firing correctly

there is a potential problem here with this formula

In Group4 Header:

Global NumberVar AccumTotal;
Local NumberVar locAccumTotal;
locAccumTotal := AccumTotal; // Save value for printing
AccumTotal := 0; // Reset accumulator
locAccumTotal // Print accumulated total

if Group 4 splits across 2 pages and the section is repeated you will prematurely reset AccumTotal to zero

you can avoid this by using Not inRepeatedGroupHeader

WhilePrintingRecords;
NumberVar AccumTotal;
NumberVar locAccumTotal;

if not inRepeatedGroupHeader then
(
locAccumTotal := AccumTotal;
AccumTotal := 0;
//use totext here so you can print a null otherwise for a result
Totext(locAccumTotal,2);
)
else
"";

other than that....this seems like an awkward report to me...it looks like you are printing the previous Group4 accumTotal in a new Group 4 header...perhaps this is some kind of "balance froward" thing but without a sample expected output it is hard to tell.




Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Thanks for you reply Jim! It was way too ugly the way I was doing it. I ended up defining 4 variables and then do conditional suppression based on the value.

Here is an example of one of them:

@Group1
If {?ReportOption} = "G" Then
{OpeninvInvoiceHist.HistCreditAcct}
Else
{LeaseDatabase.LeaseBank}

Footer Suppression
// Just in case
InRepeatedGroupHeader or
({@ReportOption} = "G" and
Previous({OpeninvInvoiceHist.HistCreditAcct}) =
{OpeninvInvoiceHist.HistCreditAcct})


Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top