Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help reducing number of IF statements 1

Status
Not open for further replies.

Jamfool

IS-IT--Management
Apr 10, 2003
484
0
0
GB
Basically if l1 is greater than the str_len then i need to take a part of the string and set str_len to 0. (Repeating this for several other fields) If it is less than str_len I want to take all the string and set str_len to str_len - l1. At the moment this is multiple IF statements. How do I make this work more simply :) I cant even get the IF statement to execute muultiple line commands :(

If (l1 >= str_len and str_len >=0) Then
String_OUT := String_OUT + LEFT({t1.Notes1},str_len);
If (l1 >= str_len and str_len >=0) Then
str_len := 0;

If l1 < str_len and str_len >=0 Then
String_OUT := String_OUT + {t1.Notes1};
If l1 < str_len and str_len >=0 Then
str_len := str_len - l1;

If (l2 >= str_len and str_len >=0) Then
String_OUT := String_OUT + LEFT({t1.Notes2},str_len);
If (l2 >= str_len and str_len >=0) Then
str_len := 0;

If l2 < str_len and str_len >=0 Then
String_OUT := String_OUT + {t1.Notes2};
If l2 < str_len and str_len >=0 Then
str_len := str_len - l2;

If (l3 >= str_len and str_len >=0) Then
String_OUT := String_OUT + LEFT({t1.Notes3},str_len);
If (l3 >= str_len and str_len >=0) Then
str_len := 0;

If l3 < str_len and str_len >=0 Then
String_OUT := String_OUT + {t1.Notes3};
If l3 < str_len and str_len >=0 Then
str_len := str_len - l3;

 
Hi,
Multiple 'if' lines is achieved using ()

eg.

if a := 0 then
(s := &quot;Zero value&quot;;
if b := 0 then
(a := 1;
b := 2;
c := 3)
else
(a := 3; c := 4)
)
else
(s := &quot;Non-zero value&quot;;
b := 99
)


IF all you are trying to achieve is rejoining these 4 notes fields then you just simply add them all in to a text field
within the report.

eg.
{t1.Notes1}{t1.Notes2}{t1.Notes3}{t1.Notes4}


PS. if you are using CR9 then you do not have the 255 string length limitation.
 


crystal 8.5 and 9 :) yup crystal was being trixy with its if statements ;p

if (x=1) then
(
y:= 1 ;
t := 2
);

needed to know where the semicolons went
 
Well first of all .... it would be nice to see all of the formula ...not just the snippet that you feel is important.
For example: how is the value of str_len initially set???

You can cut the number of IF-Then's in half by using parentheses also it would run faster by a bit by testing if
you tested for str_len >=0 once....Also should it not be that str_len > 0 ...??? If it is = 0 nothing is really done...correct?

If str_len > 0 Then
(
If l1 >= str_len Then
(
String_OUT := String_OUT + LEFT({t1.Notes1},str_len);
str_len := 0;
)
else If l1 < str_len Then
(
String_OUT := String_OUT + {t1.Notes1};
str_len := str_len - l1;
);

If l2 >= str_len Then
(
String_OUT := String_OUT + LEFT({t1.Notes2},str_len);
str_len := 0;
)
else If l2 < str_len Then
(
String_OUT := String_OUT + {t1.Notes2};
str_len := str_len - l2;
);

If l3 >= str_len Then
(
String_OUT := String_OUT + LEFT({t1.Notes3},str_len);
str_len := 0;
)
else If l3 < str_len Then
(
String_OUT := String_OUT + {t1.Notes3};
str_len := str_len - l3;
);
);

More than that I cannot tell you since it would need the rest of the formula and context of the formula within the report before I could comment....

also there should be some kind of test for 254 char if this is a possiblity


Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top