Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: understanding shared variables Post Reply Post New Topic
Author Message
Cordellv
Newbie
Newbie
Avatar

Joined: 14 Jan 2009
Location: United States
Online Status: Offline
Posts: 35
Quote Cordellv Replybullet Topic: understanding shared variables
    Posted: 20 Feb 2009 at 6:53pm
that is interesting I just read that post about the Control R deleting the text and now it happened to me by accident...  I will go type it in WORD first then repost it so I dont lose it.  Cordell
 
OK Here it is again
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am having trouble understanding sub reports. I looked in search and cannot find anything like this question.

 

 I have a report where each school employee has hours on from 1 to 3 different assignments and I have to find which assignment has the largest total hours then use the number of days worked from that largest total assignment  times the hours  for all 3 assignments (don’t ask... it is a union thing).

 

I created a sub report to display the assignments.  That worked

I put the largest total hours worked in a shared variable and that worked

Then I multiplied the total days worked by that shared variable from the largest one on the main report.

 

However just like you say in the book on page 374, the total is off by one assignment every time.

 

So I wrote a simpler report just to test it.

 

The Main report has one table called  ZipCode. 

 

I put the field ZipCode.Zip-Code on the main report in the detail section. 

 

Then I created a matching sub report with that one table and linked by ZipCode.Zip-Code. 

 

Then I created a formula  in the sub report called fmsubZipCodeState

shared stringvar ZipCodeState;

ZipCodeState := ZipCode.Zip-State;

 

I put the sub report on the main report in the detail section next to the ZipCode.Zip-Code field

 

Then I created a formula in the main report called fmmainZipCodeState

Shared stringvar ZipCodeState;

ZipCodeState;

 

and put it on the main report to the right of the sub report

 

Now on the main report detail line I have table field ZipCode.Zip-Code, the sub report (showing the 2 digit state from the sub report) and then the formula from the main report fmmainZipCodeState (showing the 2 digit state from the main report)

 

My results

09045   AL   

71823   AR    AL

85004   AZ   AR

 

What am I missing here?  I tried putting the sub report and the main report formula in the header, in the footer, in the detail… I have put so many combinations of the sub report and those two fields in the headers, footers, detail, their own header their own footer that  I am dizzy and it is still always one calculation off.


Can you help me see through the fog?  This should be so simple it should be stupid to even ask but I can’t make it work.  If I can get the zip code report to work I should be able to use the logic from that to make my school employee calculation report work (hopefully…. if I can understand arrays)….

 

Cordell



Edited by Cordellv - 20 Feb 2009 at 7:14pm
Making Things Better One Day At A time
IP IP Logged
despec99
Newbie
Newbie


Joined: 10 Feb 2009
Online Status: Offline
Posts: 22
Quote despec99 Replybullet Posted: 23 Feb 2009 at 5:43am
For the heck of it, try using the "whileprintingrecords;" command as the first line in each of your shared variables formulas.  See if that as any positive affect.

David
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 23 Feb 2009 at 6:17am
have you tried the subreport in the details and the report in a subsequent detail line?
 
think of everything in the detail line executing together...the subreport may be updating the shared variable, but the formula is using the prior value.  if you put the formula in the 'next' line, the shared variable is updated and the formula is using the most recent value.
 
try adding a second detail line by right clicking on the detail line and selecting 'Insert Section Below'
 
hope this helps
IP IP Logged
Cordellv
Newbie
Newbie
Avatar

Joined: 14 Jan 2009
Location: United States
Online Status: Offline
Posts: 35
Quote Cordellv Replybullet Posted: 23 Feb 2009 at 2:34pm
David,

You were right.  As careful as I tried to be in rebuilding the example report I did miss putting the whileprintingrecords; in the Main report formula.  I thought I had it both places.  Once I had that in both the Subreport shared variable formula and in the main report shared variable then they execute together on the detail line and I get the same state in the sub report and main report variables. It is so easy to miss such simple things then you get so close to the forest you cant see the trees... and frustration just makes it worse.  Nice to have friends here in this forum that can help cut down the trees.... Thanks Dave... now I see why they pay you the big bucks at work... ATTENTION TO DETAIL...  Cordell
Making Things Better One Day At A time
IP IP Logged
Cordellv
Newbie
Newbie
Avatar

Joined: 14 Jan 2009
Location: United States
Online Status: Offline
Posts: 35
Quote Cordellv Replybullet Posted: 23 Feb 2009 at 2:36pm

Lockwelle

I had already tried that.  But that prints the data on two different lines and I need it all on the same line.  But thanks for taking the time to try to help me.  Cordell



Edited by Cordellv - 23 Feb 2009 at 2:37pm
Making Things Better One Day At A time
IP IP Logged
Cordellv
Newbie
Newbie
Avatar

Joined: 14 Jan 2009
Location: United States
Online Status: Offline
Posts: 35
Quote Cordellv Replybullet Posted: 23 Feb 2009 at 3:27pm
How do you mark a post as answered or closed?

Cordell
Making Things Better One Day At A time
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.