What can cuase this while loop to fail, while condition true

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

What can cuase this while loop to fail, while condition true

Post by Dick99999 » Mon Jul 19, 2010 4:39 am

I cannot get the following while to work, tried many variations. The basic one below should work, or am I missing something?

When I run the code below in a 800 line long script I get the following results
- First MDL displays TRUE, displaying the before while expression
- 2nd MDL displays TRUE, displaying the same while expression directly
Yet the while is skipped. so 3-rd MDL not executed
- 4-th, 5-th MDL display True, displaying the before and after while expressions

While debugging, the var list gives:
0: WHILEAFTERVAL=TRUE
0: WHILEBEFOREVAL=TRUE
0: I=0
0: NFILES=10
0: WAITBREAK=0

Yet while loop skipped. Also tried a simple expression equivalent while loop using the beforevalue, since the MS reference does not mention complex expressions in whiles, same result.


Code: Select all

      let>whileBeforeVal={(%i%<%nFiles%) AND (%waitBreak%=0)}
      mdl>whileBeforeVal
      mdl>{(%i%<%nFiles%) AND (%waitBreak%=0)}
      while>{(%i%<%nFiles%) AND (%waitBreak%=0)}
          MDL>OK am within while
          // long code deleted
      EndWhile
      let>whileAfterVal={(%i%<%nFiles%) AND (%waitBreak%=0)}
      mdl>whileBeforeVal
      mdl>whileBeforeVal

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

Post by JRL » Mon Jul 19, 2010 1:00 pm

Also tried a simple expression equivalent while loop using the beforevalue, since the MS reference does not mention complex expressions in whiles, same result.
Don't know what simple expression you tried but this works for me. (I remarked out your MDLs and watched the watchlist as I stepped through this in the editor.)

Code: Select all

Let>i=0
Let>nFiles=10
Let>waitBreak=0


      let>whileBeforeVal={(%i%<%nFiles%) AND (%waitBreak%=0)}
      //mdl>whileBeforeVal
      //mdl>{(%i%<%nFiles%) AND (%waitBreak%=0)}
      while>whileBeforeVal=TRUE
          add>i,1
          let>whileBeforeVal={(%i%<%nFiles%) AND (%waitBreak%=0)}
          //MDL>OK am within while
          // long code deleted
          
      EndWhile
      let>whileAfterVal={(%i%<%nFiles%) AND (%waitBreak%=0)}
      //mdl>whileBeforeVal
      //mdl>whileAfterVal

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Mon Jul 19, 2010 1:02 pm

The help for WHILE does refer you to REPEAT and UNTIL for the forms the expression may take. It is looking for a variable and a value.

Did you try something like this?

Code: Select all


Let>whileval={complex expression}
While>whileval=TRUE
   Let>whileval={complex expression}
   do something
Endwhile
Gale

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Mon Jul 19, 2010 9:27 pm

When I reduce the script to while only, the while is working. Thanks for pointing that out. I also tried the set value, simple while test as given above. They work but not in my script. So something must interfere.
I just wondered whether "before true condition, while not executing, after true" does ring a bell where to look for what type of error.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Mon Jul 19, 2010 9:42 pm

You have 800 lines of code in your real script. There may be a syntax error in there somewhere. Make sure all of your braces, brackets, paranthesis, and quotes balance. Otherwise the script will run out of code before finding the EndWhile statement.

Gale

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Tue Jul 20, 2010 5:47 am

Sorry, I was to fast with "the short code works" conclusion. It seems that the complex expression is not allowed as a while condition. The following code (thanks) only gives 'we are out', never within the loop. (MS v12 on win XP)

B.t.w. the repeat loop explicitly mentions the (fairly limited) expressions allowed in the until (command reference help).

So pre-setting the while condition to a var before and at the end of the while, seems the way to go, see JRL's posting

Code: Select all


Let>i=0
Let>nFiles=10
Let>waitBreak=0

      let>whileBeforeVal={(%i%<%nFiles%) AND (%waitBreak%=0)}
      while>{(%i%<%nFiles%) AND (%waitBreak%=0)}

          mdl>within the while
          add>i,1
      EndWhile

mdl>we are out

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Thu Jul 22, 2010 12:48 pm

Dick99999 wrote:Sorry, I was to fast with "the short code works" conclusion. It seems that the complex expression is not allowed as a while condition. The following code (thanks) only gives 'we are out', never within the loop. (MS v12 on win XP)

B.t.w. the repeat loop explicitly mentions the (fairly limited) expressions allowed in the until (command reference help).
[........]
Found the following in the help file
"Complex expressions are supported in Macro Scheduler's IF statements and LET statement, and since version 9.0 can now also be included within all other commands and function calls in the place of regular variables."

So if the while case above is indeed not working, it seems to be a bug. As is the remark about permitted repeat until expressions.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Fri Jul 23, 2010 2:25 pm

The Repeat and While statements currently require a variable to compare against a simple or complex expression. Try this:

Code: Select all

Let>i=0
Let>nFiles=10
Let>waitBreak=0
Let>whileBeforeValue=TRUE

      while>whileBeforeValue={(%i%<%nFiles%) AND (%waitBreak%=0)}

          mdl>within the while
          add>i,1
      EndWhile

mdl>we are out

Try this also:

Code: Select all

Let>i=0
Let>nFiles=10
Let>waitBreak=0

      while>TRUE={(%i%<%nFiles%) AND (%waitBreak%=0)}

          mdl>within the while
          add>i,1
      EndWhile

mdl>we are out
The above is untested, I'm not at my MS machine - I am out too.

Gale

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Mon Jul 26, 2010 11:25 am

Unfortunately both result in 'we are out' only

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jul 26, 2010 12:00 pm

You can do this:

Code: Select all

Let>i=0
Let>nFiles=10
Let>waitBreak=0
Let>whileBeforeValue=TRUE

      while>whileBeforeValue=TRUE
          //mdl>within the while
          add>i,1
          Let>whileBeforeValue={(%i%<%nFiles%) AND (%waitBreak%=0)}
      EndWhile

mdl>we are out
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

Post by Dick99999 » Fri Oct 01, 2010 6:46 am

mtettmar wrote:You can do this:

.............
Since the discussion about the while is current again, the code above is not equivalent to a while. Should be something like:

Code: Select all

Let>i=0
Let>nFiles=10
Let>waitBreak=0
//
          Let>whileBeforeValue={(%i%<%nFiles%) AND (%waitBreak%=0)}

//

      while>whileBeforeValue=TRUE
          //mdl>within the while
          add>i,1
          Let>whileBeforeValue={(%i%<%nFiles%) AND (%waitBreak%=0)}
      EndWhile

mdl>we are out

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