Solved

Crystal Reports shared variable from sub report not passing value

Posted on 2014-12-05
19
781 Views
Last Modified: 2014-12-07
I have main report rptStudent and sub report rptSubStudentGrade
Main report has RH,PH,GH1a,GH1b,GH1c.
In GH1a I put sub report rptSubStudentGrade . In rptSubStudentGrade in detail section I have formula with shared variable.
@PassStdGrade:
WhilePrintingRecords;
Shared StringVar  StdGrade;
StdGrade:= fldStudentGrade;
StdGrade;
I am Re- setting this variable in rptSubStudentGrade  Header section in formula @ResetPassStdGrade:
WhilePrintingRecords;
Shared StringVar StdGrade;
StdGrade:=””;
StdGrade;

In main report in GH1b I want to display value of shared variable StdGrade and I created formula @DispGrade:
WhilePrintingRecords;
Shared StringVar StdGrade;
StdGrade;

Main report group is based on StudentID and that is parameter connection field that sub report rptSubStudent is connected with main report.
I can see  propert values in sub report in formula @PassStdGrade but that value is not  coming in main report.
Value is from field fldStudentGrade but not proper one.???
0
Comment
Question by:Taras
  • 9
  • 6
  • 4
19 Comments
 
LVL 34

Expert Comment

by:James0628
ID: 40484485
The first thing would be that if you're setting the variable like that in the detail section of the subreport, then at the end of the subreport, the variable will just have the value from the last record in the subreport.  Assuming that the subreport is reading more than one record each time it runs, do all of the records have the same value in the field in question?  If not, will the last record have the value that you're looking for?

 Also, you said that @ResetPassStdGrade was in a "header section" in the subreport, but do you mean a report header section or a group header?

 Also, FYI, if there are ever times when a subreport does not read _any_ records (there are no records for a student), your variable may not be changed by the subreport.  It seems that at least some subreport sections may not be "processed" when there are no records.  If that could be an issue, you could reset the variable (set it to "") in a separate GH1 section in the main report, before the section containing the subreport, just to make sure.

 James
0
 

Author Comment

by:Taras
ID: 40484666
I will add more detail, suppose I should do that at begging.I appologize.

Sub report and main report are connected through SudentID that is group field in main report, I said that.
As I understand when sub report is run it is run for that particular studentID.
Each student has several Courses. I am puling grade for each of them, here I am talking about English class grade.
So on detail line of sub report  I have formula.
@GetStdGrade:
WhilePrintingRecords;
Shared StringVar GetStdGrade;
If fldStudentCourseID = “English” then
GetStdGrade:= fldCourseRate
Else
GetStdGrade:=””;
GetStdGrade;

So this formula with this  variable  is executed several times and formula - variable will have last value in when detail section of sub report is executed.
This last value is not good.
To avoid this I added another formula @PassStdGrade to catch(pass proper value  to shared “clean”variable named StdGrade) .

So after formula GetStudentGrade catch value I am loking for I am passing that to shared variable through formula @PassStdGrade which is located in detail section of subreport too , just after GetStdGrade formula.

And formula looks like this:
@PassStdGrade:
WhilePrintingRecords;
Shared StringVar StdGrade;
If fldStudentCourseID = “English” And @GetStudentGrade  <> ”” then
StdGrade:= fldCourseRate;
StdGrade;

But still not getting proper value.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40484890
Are you trying to get the grade for a particular subject passed back to the main report?

Do you need to display the grades for all subjects in the subreport?

mlmcc
0
 

Author Comment

by:Taras
ID: 40484912
Yes I am trying to get grade for particular subject passed to main report.
I need to pull grades for other subjects too. This was just example for English.

Sub report will be suppressed and not visible .Grades will be displayed in Main report.
0
 
LVL 34

Expert Comment

by:James0628
ID: 40485050
You used the names @GetStdGrade and @GetStudentGrade.  I'm guessing that those are the same thing, but if not, what is in @GetStudentGrade ?

 You said that @PassStdGrade is in a detail section and "just after" @GetStdGrade.  Are they in the same detail section, or different detail sections?  If @PassStdGrade is in the same section, there's no guarantee that it will be evaluated after @GetStdGrade.  You could put @PassStdGrade in a separate detail section, or use the EvaluateAfter function in @PassStdGrade, to force it to be evaluated after @GetStdGrade.

 Having said that, I don't really see the need for the second formula, if they're both in a detail section.  That's assuming that @GetStudentGrade in the second formula is really referring to the first formula, @GetStdGrade.

 Why not just remove the Else from @GetStdGrade?  The way you have it, if it's English, you put the grade in GetStdGrade.  Otherwise, you set GetStdGrade to "".  If you leave off the Else, GetStdGrade will be set when it's English, and left unchanged when it's not.  Then at the end of the subreport, GetStdGrade should have the grade from the last English record, if there were any.  I don't think you need the second formula to try to save the English grade in a separate variable.

 James
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40485068
Can you upload the rpt file?

mlmcc
0
 

Author Comment

by:Taras
ID: 40485116
James, @GetStdGrade and GetStudentGrade is the same formula , not two but one formula @GetStdGrade. It was typo.
I tried as you suggested to put PassStdGrade in separate detail section below section where is GetStdGrade and it did not work.
Problem is I am getting the same grades for English,French,Math. I am having each of these set of formulas for each student course(English, French, Math,….)
Each set of formulas:
(@GetStdGrade_English,@PassStdGrade_English,ResetPassStdGrade_English)
(@GetStdGrade_French,@PassStdGrade_French,ResetPassStdGrade_French)
(@GetStdGrade_Math,@PassStdGrade_Math,ResetPassStdGrade_Math)
All GetStdGrades formulas are in one detail section e.g. Da of sub report.
And I put all PassStdGrades formulas in Db.
And I put all ResetPassStdGrades formula in in sub report header.
And what I have now  something like this.
I am having 10 courses. It means it will be ten lines in detail section.
Titles line
CourseID    CourseGrade    CourseComment

On first line;
English        90                student is showing English skills this and that…..      
GetStdGrade_English= 90 GetStdGrade_French=90 GetStdGrade_Math = 90………the same patern
On second line;
____________________________________________________________________________________
French             85               Student is showing French skills this and …….
GetstdGrade_English = 85 GetStdGrade_French = 85 GetStdGrade_Math = 85
 Third line
____________________________________________________________________________________
Math          65              student is showing in math this and that…….
GetStdGrade_Englis = 65 GetStdGrade_French=65 GetStdGrade_Math = 65
And on and on…..
What has to happen on those lines only one GetstdGrade has to have value  and it should be that one that course is present other GetStdGrades on that line has to be empty.
Somehow I can not  reset values.
I tried different scenarios in sub report :  to do  grouping on StudentID then on CourseID  and moved formulas GetStdGrades in  GH1a of CourseID  and moved formulas PassStdGrades in GH1b (of CourseID group)  but I am getting the same grades in all GetStdGrades formulas per section a,b,c
Then I moved this on groups footer and got the same results….
0
 

Author Comment

by:Taras
ID: 40485133
mlmcc.
I do not have experience with this upload procedure. How it works?

If I upload rpt file will data be available visible or just report design without data?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40485186
If you save the report with data, then the data will be visible.  You can save reports without data in which case only the report structure and formulas are available.

Just click the ATTACH FILE link
Browse to the file
Click OPEN
Click UPLOAD
Add a comment
Click SUBMIT

mlmcc
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Taras
ID: 40485209
mlmcc.
This is just beginning of work on this report and lot staff is missing I am focused now on sub report (SubRepSem1) to get those course values for first semester in main report. Then I will work on sub report 2 for second semester that has the similar structure with small changes.
Report-Card-12-06-14-Test.rpt
0
 

Author Comment

by:Taras
ID: 40485671
???
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40485714
For some reason Crystal files get uploaded with a HTM extension.  To download you have to right click and choose SAVE AS then change the extension

mlmcc
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 40485729
First issue.  All the variables have to be declared as SHARED

Shared StringVar EngGrade;

I'll continue looking but make those changes and see if it works

mlmcc
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 200 total points
ID: 40485738
You are making this much more difficult than it needs to be.

The only formul you really need in the subreport is the SET

WhilePrintingRecords;
Shared StringVar EngS1G;

If InStr({StsGrdsGrds_1.StsGrdsGrds_1_ClassID}, "ENG") >= 0 Then
    EngS1G:= {StsGrdsGrds_1.StsGrdsGrds_1_Grade};

Open in new window


If you want to ensure you get the grade if it exists and a blank/NULL string if it doesn't then reset the grade in the subreport report header with

WhilePrintingRecords;
Shared StringVar EngS1G;
EngS1G := "";

Open in new window


mlmcc
0
 
LVL 34

Accepted Solution

by:
James0628 earned 300 total points
ID: 40485779
For some reason Crystal files get uploaded with a HTM extension.  To download you have to right click and choose SAVE AS then change the extension
FWIW, unless you somehow "fixed" his u/l'ed file, I think that may be a browser thing.  I d/l'ed his report with Firefox and it had the .rpt extension.  I didn't have to do anything.  But I've d/l'ed other reports from EE using IE and they ended up with the HTML extension.


 Taras,

 From what I've seen, all of your variables do _not_ have to be shared.  For example, I think you're only using GetEngS1G inside the subreport.  If so, it can be global (the default).  Only the variables that you want to reference in both the main report and the subreport need to be shared.

 As mlmcc and I both mentioned, you do seem to be making things a bit more complicated than necessary.  But, aside from that, I think I have spotted a problem.

 In formulas like GetSem1EngGrade, you're checking for InStr (<stuff>) >= 0.  Equal to 0 means that the string was not found.  IOW, you're _always_ setting your "intermediate" variable (eg. GetEngS1G), whether or not the target string (eg. "ENG") was found.

 Try changing all of those InStr (<stuff>) >= 0 tests to just > 0, so that you only set the variables when the desired course is included in the field.

 James
0
 

Author Comment

by:Taras
ID: 40485780
mlmcc.
I did as you suggested I am checking value just now for three courses English,French and Math.
I am getting the same value for all of them per one detail  line(as I described before), it looks like it is not re setting values.
0
 

Author Closing Comment

by:Taras
ID: 40485783
Thanks both of you. James it was that >=0 that made problem.
0
 
LVL 34

Expert Comment

by:James0628
ID: 40485860
You're welcome.  FWIW, if you had posted your actual formulas earlier, we might have figured this out sooner.  The formulas that you posted earlier just had fldStudentCourseID = “English”, which looked fine, but then it turned out that your actual test was different.  Just something to keep in mind for the future.  We can only go by the information that you give us.

 James
0
 

Author Comment

by:Taras
ID: 40485896
Sub report working now fine, however now I can not pass shared variable in main report. I will put next question with this problem.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now