Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Array Question, please help Post Reply Post New Topic
Author Message
mvaughn
Newbie
Newbie
Avatar

Joined: 09 Oct 2007
Location: United States
Online Status: Offline
Posts: 16
Quote mvaughn Replybullet Topic: Array Question, please help
    Posted: 06 Oct 2009 at 9:56am
I am trying to show a "disclaimer" in a formula field in the page footer of a report based of values in me detail section.  Currently I hace this in a formula field called GradeArray which I have placed in my detail section and suppressed so it doesn't print.
 
whileprintingrecords;
stringvar array GradeArray;
numbervar Counter;
if not ({@Grade} in GradeArray) then
(Counter := Counter +1;
if Counter < 1000 then
(Redim Preserve GradeArray[Counter];
GradeArray[Counter] := {@Grade}))
 
 
What I need to do is  access the GradeArray in the footer and see if it equals
41S42, 41F42, 41H42 or 41X40.  I can have anywhere from 1 detail line to 50.  Am I building the array correctly and if so how do I access from the footer  in the formula field to show the text if any of teh values has been added to the array?
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 06 Oct 2009 at 10:24am
You can modify to array declaration to increase its scope. Using 'Global' will make a variable accessible throughout your report. Using 'Shared' will make it accessible to subreport (not relevent here, but good to know for the future). You could change your variable declaration to the following:

Global stringvar array GradeArray;

Note that you have to include this same variable declaration in every formula that needs to use the variable. If you leave it out, the formula won't recognize the variable.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
mvaughn
Newbie
Newbie
Avatar

Joined: 09 Oct 2007
Location: United States
Online Status: Offline
Posts: 16
Quote mvaughn Replybullet Posted: 06 Oct 2009 at 10:33am
Still not working, this is what i have now
FORMULA FIELD GradeArray------
whileprintingrecords;
Global stringvar array GradeArray;
numbervar Counter;
if not ({@Grade} in GradeArray) then
(Counter := Counter +1;
if Counter < 1000 then
(Redim Preserve GradeArray[Counter];
GradeArray[Counter] := {@Grade}))
FORMULA FIELD Disclamier ---------
whileprintingrecords;
Global stringvar array GradeArray;
if "41S42" in {@GradeArray} then
'Note: 4140 products are difficult to weld. If the 4140 products on this quote are for a welding application, a qualified weld engineer should be consulted.'
For grins I added a formula field in the footer with this code
whileprintingrecords;
Global stringvar array GradeArray;
join(GradeArray,",")
 
when i run the report I get
41S42,01025 from the formula, so why doesn't my "Note" line show up?
 
IP IP Logged
mvaughn
Newbie
Newbie
Avatar

Joined: 09 Oct 2007
Location: United States
Online Status: Offline
Posts: 16
Quote mvaughn Replybullet Posted: 06 Oct 2009 at 10:38am
Found it! in the disclaimer formula field, should be if "41S42" in GradeArray then.  Last part of the question if I need to look for other strings can I do
 
if "41S42" in GradeArray or "41H42" in Grade Array then
do something
 
or should I use multiple in statements?
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 06 Oct 2009 at 2:04pm
yes, you can join the conditions into one IF statement.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
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.