Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: For Do Loop - variable assignment Post Reply Post New Topic
Author Message
wk1234
Newbie
Newbie
Avatar

Joined: 15 Jan 2013
Location: United States
Online Status: Offline
Posts: 2
Quote wk1234 Replybullet Topic: For Do Loop - variable assignment
     Posted: 15 Jan 2013 at 5:03am
I inherited a report from previous employee, and I am trying to see the logic of variable assignment.
I think the formula works in the report, but I have not tested it.
The author names stringvar, then has a Do Loop based on upper bounds of parameter list.

I want to do something similar, but I do not understand the variable assignment and piece.

Here is the code. I will flag the piece I am uncertain with using ^. I will add my comments to //

numberVar i := 0;
stringVar sParam_Site := "";

for i := 1 to ubound({?Site}) do //I assume this gets //the total number of parameters chosen from parameter //list

sParam_Site := sParam_Site + {?Site} [ i ] + ",";
......................~~~~...........................^//I am not sure how the ?Site param and the [ i] interact. I see that +"," is used to build comma separated string.

sParam_Site := Left (sParam_Site, length(sParam_Site) - 1);

if {?Site}[1] = "*" then sParam_Site := "*";

sParam_Site;

If someone could help me understand the logic here, it will help me become a better programmer.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 15 Jan 2013 at 6:40am
when you multiselect the values for a parameter, CR stores the selections in an array.
 
the code defines a counter(index) and a string to store the total of the sites selected by the user.
 
the [ i ] is the index of the array, so the output is yyy,xxx,zzz,
 
you then strip the last comma off of the string.
 
finally, if the first parameter is the asterick, forget about what was written into the string, just use the asterick.
 
display your results.
 
HTH
 
just because I am lazy, I will usually format a string like this as ,zzz,yyy,2ww 
this way, when it is time to display, I just use mid(variable, 2).
 
Also, I would check if the first array member is *, if so, skip the loop all together. It probably won't save much processing time.
 


Edited by lockwelle - 15 Jan 2013 at 6:42am
IP IP Logged
wk1234
Newbie
Newbie
Avatar

Joined: 15 Jan 2013
Location: United States
Online Status: Offline
Posts: 2
Quote wk1234 Replybullet Posted: 15 Jan 2013 at 7:58am
Thanks for such a fast response! I have read the forum before, but this was my first post and it was answered so quickly.
So, the sParam_Site := sParam_Site + {?Site} [ i ] is basically looking at the index number of i, so that it walks down the array as the loop cycles through all the parameters chosen...
Makes sense. Just did not know what I was seeing, but now clear as a bell.
Thanks again.
IP IP Logged
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