Odd looping using IfWindowOpen>

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Odd looping using IfWindowOpen>

Post by Phil Pendlebury » Sat Dec 08, 2007 3:10 pm

In order to test this please open a Notepad default window (with Untitled as file name.)

I have had major trouble with this. I am sure it something obvious. I have got around it by adding some lines but would like to know exactly what is going wrong.

By my reckoning The first loop should check for the value of loopone and as it is not ONE it should then go to the second loop group.

However, as you can see if you run the macro - it goes straight to the second part of group one.

I realise that this has something to do with the ",," but I found that in another part of my script if I removed the commas it seemed to detect any open window.

I hope this makes sense.

Code: Select all

Let>loopone=TWO

// First Group
IF>loopone=ONE
  IfWindowOpen>Untitled*,,
    msg>Hi there this is loop ONE
  ENDIF
  IfWindowOpen>Untitled*,,
    msg>Hi there this is loop ONE
  ENDIF
GOTO>END
ENDIF



// Second Group
IF>loopone=TWO
  IfWindowOpen>Untitled*,,
    msg>Hi there this is loop TWO
  ENDIF
  IfWindowOpen>Untitled*,,
    msg>Hi there this is loop TWO
  ENDIF
ENDIF

GOTO>END

Label>END
Phil Pendlebury - Linktree

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

Post by Marcus Tettmar » Sat Dec 08, 2007 3:14 pm

Yes, it is the commas. By having the commas there you are telling it to use the If>condition,truelabel,falselabel format. So the next Endif is considered belonging to the first If statement - IF>loopone=ONE. So, you will see exactly what is happeningh when you step through with the debugger. As you step through, when you get to If>loopone=ONE the debugger skips to the next Endif. It skips to line 7 because it ignores the If with the commas, because it has commas.

The commas won't make a blind bit of difference to whether it finds the window or not. But if you want to use If/Else/Endif then you should not use the commas.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by Marcus Tettmar » Sat Dec 08, 2007 3:47 pm

Incidentally, for v10 I will look at making sure the code builder does not insert commas when you insert an If statement but leave the label fields blank. I can see why it doing this may be causing some people confusion and leading to a scenario where people are inserting "If>condition,,". I'll also have the If/Else/Endif parsing looked at so that where an If statement has empty labels it is ignored and treated as a regular non-label If statement as being part of an If/Else/Endif block.

But to clarify what the help file says. If statements can EITHER be:

If>condition,true_label[,false_label]

OR

If>condition
[Else]
Endif

An Else section is optional.

You should NOT mix them. E.g. the following is NOT correct:

If>condition,,
Endif

Neither is this:

If>condition,label
Endif

If you do that then presently that Endif will be treated as belonging to a previous If statement if one exists (without commas).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Sat Dec 08, 2007 3:52 pm

Thank you Marcus.

I only recently added all the commas - because I thought I had been doing something wrong due to the exact reason you mention in the (codebuilder).

Very helpful to have suspicions confirmed so quickly.

Thank you once again.

:-)
Phil Pendlebury - Linktree

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