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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested If Else 1

Status
Not open for further replies.

Halliarse

IS-IT--Management
Jan 8, 2007
213
GB
Good Afternoon Experts!

I have a text field that I only want to print certain lines of. The start line is fixed as line 4, however the last line is dependant of where a certain string sits within the text field afetr line 6. The formula below is what I want to acheive but Crystal is telling me that from the first 'else', that the text does not appear to be part of the formula. I'm pretty sure that this is going to be a parenthesis issue and I've tried several changes but to no avail....any help please? Thanks Seteve

stringvar array x := split({v_extradatacomputers1.TaskList SBS},chr(10));
numbervar i;
stringvar Result;
for i:= 4 to {@RowCount} do
if i < 6 then
result := result + x;
else
if i > 6 then
if instr(x, '==========') > 0 then
i = {@RowCount};
else
result := result + x;
else
result := result + x[6];

Result;
 
If it is a nested if issue, try:

stringvar array x := split({v_extradatacomputers1.TaskList SBS},chr(10));
numbervar i;
stringvar Result;
for i:= 4 to {@RowCount} do
if i < 6 then
result := result + x;

else if i > 6 then
(​
if instr(x, '==========') > 0 then

i = {@RowCount};​
else​
result := result + x;

)​
else
result := result + x[6];​

result;
 
Also:

maybe this:
i = {@RowCount};
needs to be:
i := {@RowCount};
 
Hi Andy

Thanks for the response and apoligies for the delay in mine, I'be been sunning myself!

I've tried your solution but I'm getting an error on the formula compile. It's stating that from the 'else if i > 6 then' inclusive, the remaining text does not appear to be part of the formula.

I've tried various changes but I can't see what's wrong with it!

Any help will be greatly appreciated.

Thanks

Steve
 
I believe the semi-colon at i = {@RowCount}; should be removed. The semi-colon rules can be confusing.
 
Hi Kray4660

This made no difference

Cheers

Steve
 
Did a little bit of experimenting and came across a big issue.

if instr(x, '==========') > 0 then
i := {@RowCount}
else
result := result + x

The if statement has to 'return' the same data type. You are setting an integer to a value and a string to a value. I do not remember if you can get around this by using Basic syntax.


Also your for loop is not set up correctly for Crystal Syntax

For i:= 4 to {@RowCount} Do
(
Statements
)
 
I reworked the formula into Basic syntax. I do not know if it works correctly, but at least no syntax errors.

Dim x() as string
x = split({Command.resourcelastname},chr(10))
dim i as number
dim Result as string

for i= 4 to {@RowCount}
if i < 6 then
result = result + x(i)
else
if i > 6 then
if instr(x(i), "==========") > 0 then
i = {@RowCount}
else
result = result + x(i)
end if
else
result = result + x(6)
end if
end if

next i
formula = result
 
Hi Kray4660

I came to the same conclusion as you regaring the 'type' issue within the formaula.

I've replaced the formaula with what you have just supplied and I do get a sysntax error....it states that the whole formula does not appear to be part of the formula....am I missing the point here?

Thanks for your continued help!

Steve
 
I forgot in testing I replaced the one field name with an existing one that I had in a database.

Dim x() as string
x = split(v_extradatacomputers1.TaskList SBS},chr(10))
dim i as number
dim Result as string

for i= 4 to {@RowCount}
if i < 6 then
result = result + x(i)
else
if i > 6 then
if instr(x(i), "==========") > 0 then
i = {@RowCount}
else
result = result + x(i)
end if
else
result = result + x(6)
end if
end if

next i
formula = result

See if this works better. FYI: I did not get any syntax errors. Be sure to use the Basic syntax.
 
I amended your formula as follows:

Code:
stringvar array x := split({v_extradatacomputers1.TaskList SBS},chr(10));
numbervar i;
stringvar Result;
for i:= 4 to {@RowCount} do
(
    IF      i < 6 
    THEN    Result := Result + x[i]
    ELSE    
    IF      i > 6 
    THEN    IF      instr(x[i], '==========') > 0 
            THEN    (i := {@RowCount}; '')
            ELSE    Result := Result + x[i]
    ELSE    Result := Result + x[6]
);
Result;

It is accepted and does return data. Not absolutely certain the result is what you want but hopefully it gets you closer.

Cheers
Pete


 
Thanks Pete

I got it to work, had to add Result := ''; as it was concatenating acroos records!

Cheers

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top