简体   繁体   中英

How to use loop for in a formula in crystal report?

I have a table in the details section with 3 columns (ID_Player, Name Player, medal) the medal column take gold, silver or bronze. and in the header page section i have 3 images for each type of medal i need to display the images according to the medal value displayed in the details section??

I try: in the supression option of the image 1 (gold):

numbervar i ;
for i:=1 to count({table.medal}) do
(
if ({table.medal} = "gold") then false else true
)

the same code for the 2 others images but always it read only the first record !!

You have to check the existence of a medal in separate formula that will be evaluated for all the records and pass the result as a global variable to suppress formula:

formula hasMedal:

Global NumberVar num_var;
If {table.medal} = "gold" Then
num_var := 1

formula for suppress:

EvaluateAfter({@hasMedal});
Global NumberVar num_var;
num_var = 0;

In your current for-loop the NumberVar i goes through all the values but {table.medal} is pointing at the first row the whole time.

You can not iterate for loop to display images bcoz it it refer to the current row.. you have to use nested if...else..to display image...

 if ({table.medal} = "gold") then 
     false 
else if ({table.medal} = "silver ") then
     false
else if ({table.medal} = "bronze") then    
     false   
else
     true

i try to put @hasmedal in the details section when gold value exist hasmedal take 1 else it take 0 . same thing for the other value (silver and bronze) i have now 2 lines: the first line contain gold and the second contain silver .. the hasmedalGold appears 1 in the first line and 0 in the second line . and the hasmedalSilver appears 0 in the first line and 1 in the second... and hasmedalBronze appears 0 in the 2 lines in the supress formula i put this code :

    EvaluateAfter({@hasmedalGold});
Global NumberVar num_var;
num_var <> 0;
if ({@hasmedalGold} =1)
then false else true   

                                                                                              but the problem persist it display only the gold medal which is in the first line record :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM