Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: using for loop and nested if in formula Post Reply Post New Topic
Author Message
hptk
Newbie
Newbie
Avatar

Joined: 17 Jun 2011
Location: United States
Online Status: Offline
Posts: 3
Quote hptk Replybullet Topic: using for loop and nested if in formula
     Posted: 17 Jun 2011 at 8:56am
Hello there:
 
I'm trying to read in a String array that contains data like ',0,1,2,3,...' that represents days of the week and translate the string array into a raw text string that spell out the code.
 
This code below works only when the array only contain 1 value like ',2,' but doesn't work when the array has more than one values like ',2,3,4,'.
 
Do you have any idea why? Logically, it makes sense, but perhaps I'm missing something? Any help is appreciated.
 
Local StringVar inString := {rsCustomProgram.Days};
Local StringVar outString := "";
Local StringVar finalString := "";
Local NumberVar i;
For i := 1 To Length(inString) Do
( if ({rsCustomProgram.Days} like ',0,')
    then outstring:= "Monday"
else if ({rsCustomProgram.Days} like ',1,')
    then outstring:= "Tuesday"
else if ({rsCustomProgram.Days} like ',2,')
    then outstring:= "Wednesday"
else if ({rsCustomProgram.Days} like ',3,')
    then outstring:= "Thursday"
else if ({rsCustomProgram.Days} like ',4,')
    then outstring:= "Friday"
else if ({rsCustomProgram.Days} like ',5,')
    then outstring:= "Saturday"
else if ({rsCustomProgram.Days} like ',6,')
    then outstring:= "Sunday"
else
    outstring:= "");
finalString := outString + finalString;
finalString
IP IP Logged
hptk
Newbie
Newbie
Avatar

Joined: 17 Jun 2011
Location: United States
Online Status: Offline
Posts: 3
Quote hptk Replybullet Posted: 20 Jun 2011 at 3:42am
So I learned about the lookslike function and changed my for loop into the following:
 
Local StringVar inString := {rsCustomProgram.Days};
Local StringVar outString := "";
Local StringVar finalString := "";

if lookslike({rsCustomProgram.Days},'*,0,*')
then outstring:= "Monday";

if lookslike ({rsCustomProgram.Days},"*,1,*" )
    then outstring:= outstring + ", " + "Tuesday";

if lookslike({rsCustomProgram.Days},"*,2,*")
    then outstring:= outstring + ", " + "Wednesday";

if lookslike({rsCustomProgram.Days},'*,3,*')
  then outstring:= outstring + ", " + "Thursday";

if lookslike({rsCustomProgram.Days},'*,4,*')
  then outstring:= outstring + ", " + "Friday";

if lookslike({rsCustomProgram.Days},'*,5,*')
   then outstring:= outstring + ", " + "Saturday";

if lookslike({rsCustomProgram.Days},'*,6,*')
   then outstring:= outstring + ", " + "Sunday";

finalString := outString + finalString;
finalString

However, what it's giving me now is everything! Doesn't matter what is in rsCustomProgram.Days, it gives me the whole Monday-Sunday string as the result. What am I doing wrong? Crystal totally confused me. Perhaps there is some kind of problem with the syntax?
IP IP Logged
hptk
Newbie
Newbie
Avatar

Joined: 17 Jun 2011
Location: United States
Online Status: Offline
Posts: 3
Quote hptk Replybullet Posted: 20 Jun 2011 at 4:06am
NVM, I figured it out. It's like this:
 
Local StringVar inString := {rsCustomProgram.Days};
Local StringVar outString := "";
Local StringVar finalString := "";
if {rsCustomProgram.Days} like "*,0,*"
then outString := outString + ", Monday";
if {rsCustomProgram.Days} like "*,1,*"
then outString := outString + ", Tuesday";
if {rsCustomProgram.Days} like "*,2,*"
then outString := outString + ", Wednesday";
if {rsCustomProgram.Days} like "*,3,*"
then outString := outString + ", Thursday";
if {rsCustomProgram.Days} like "*,4,*"
then outString := outString + ", Friday";
if {rsCustomProgram.Days} like "*,5,*"
then outString := outString + ", Saturday";
if {rsCustomProgram.Days} like "*,6,*"
then outString := outString + ", Sunday";
finalString := outString;
finalString
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