INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Nested If Else

Nested If Else

(OP)
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[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;

RE: Nested If Else

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[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;

RE: Nested If Else

Also:

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

RE: Nested If Else

(OP)
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

RE: Nested If Else

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

RE: Nested If Else

(OP)
Hi Kray4660

This made no difference

Cheers

Steve

RE: Nested If Else

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

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

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
)

RE: Nested If Else

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

RE: Nested If Else

(OP)
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

RE: Nested If Else

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.

RE: Nested If Else

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

RE: Nested If Else

(OP)
Thanks Pete

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

Cheers

Steve

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close