Nested If> Loops

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Nested If> Loops

Post by tony_smith » Wed Oct 19, 2005 10:30 pm

I have looked through previous posts and they do not satisfy my question.

The following seems to work just fine, but is it "legal"?

I can't find a reference to nesting IF statgements in this manner and want to be cautious...


Remark>Pare MIT line down to fit 9 chars
If>MITCNTLG=4
Let>Let>MITLN=00090%MITCNT%%SPRFILE%
ELSE
If>MITCNTLG=3
Let>MITLN=000900%MITCNT%%SPRFILE%
Else
If>MITCNTLG=2
Let>MITLN=0009000%MITCNT%%SPRFILE%
ENDIF

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Oct 20, 2005 3:30 am

I can't satisfy your question either but I hate to use a bunch of if's where there's a logical relationship so maybe something like:

Let>MITCNTLG=6-MITCNTLG
MidStr>9000,1,%MITCNTLG%,begin
Let>MITLN={"000"+%begin%+%MITCNT%+%SPRFILE%}

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Oct 20, 2005 4:11 am

This script as posted runs without any results so I assigned a value of 4 to MITCNTLG and got an error saying that EndIf was missing.

I think you can nest "IF" statements any old way that suits you but you must have an "ENDIF" for every "IF"

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Oct 20, 2005 8:10 am

JRL is correct. Your script is invalid as there are not enough EndIfs. Each If must have an Endif.

Perhaps you meant:

Remark>Pare MIT line down to fit 9 chars
If>MITCNTLG=4
Let>MITLN=00090%MITCNT%%SPRFILE%
Else
If>MITCNTLG=3
Let>MITLN=000900%MITCNT%%SPRFILE%
Else
If>MITCNTLG=2
Let>MITLN=0009000%MITCNT%%SPRFILE%
EndIf
EndIf
EndIf

Although this would also work in this case:

Remark>Pare MIT line down to fit 9 chars
If>MITCNTLG=4
Let>MITLN=00090%MITCNT%%SPRFILE%
EndIf
If>MITCNTLG=3
Let>MITLN=000900%MITCNT%%SPRFILE%
EndIf
If>MITCNTLG=2
Let>MITLN=0009000%MITCNT%%SPRFILE%
EndIf


No real need for elses here since if MITCNTLG=4 it can't be 3 or 2, so each bit can be sequential.

Both versions above are valid.
MJT Net Support
[email protected]

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Post by tony_smith » Thu Oct 20, 2005 3:09 pm

Thanks to all who responded... lots of ideas and guidance.

It is feedback like this that shows the value of these forums, something I wish other mission-critical software would have.

The lack of endifs is a rookie mistake on my part... oops! My trial values did not test all the loops.

Also, I made a typo by duplicating the let command;

Let>Let>MITLN=00090%MITCNT%%SPRFILE%

:oops:

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts