Jump to content
Macro Express Forums

The Repeat Until and End Repeat function


Recommended Posts

All, I'm running a simple macro illustrated below..

 

<LAUNCH PROGRAM AND ACTIVATE WINDOW Title="TV" Exact_Match="FALSE" Wildcards="FALSE" Path="C:\\Program Files\\ATI Multimedia\\main\\ATIMMC.EXE" Mode="\x00" Default_Path="TRUE" Wait="1" Wait_For_Program="12"/>
<TEXT TYPE Action="0" Text="<F3>"/> ;removes application window border and screen controls
<WAIT FOR TIME TO ELAPSE Hours="0" Minutes="1" Seconds="0"/> ;1 min is for testing purposes
   <IF MESSAGE Caption="CNN" Message="Are you still watching CNN?" BtnMode="\x00" Default="FALSE" Delay="10"/>
   <WAIT FOR TIME TO ELAPSE Hours="0" Minutes="1" Seconds="0"/>
<ELSE/>
<TEXT BOX DISPLAY Title="CNN" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 CLosing CNN\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x01" Delay="5"/>
<END IF/>
<TERMINATE PROCESS Window="FALSE" Name="ATIMMC.EXE" Partial="TRUE" Wildcards="FALSE" Timeout="1000"/>

 

The streaming video is brought up and runs for a short period or time. To determine if anyone is still watching the streaming video i display a message box. If the user clicks on the "yes" button in the message box the video app continues to run. After the "wait for time to expire" elapses the video app closes. I want to repeat (loop) this somehow so that as long as the user continues to click on the "yes" button the video app will continue to run. The default response to the "IF Message" is "no". If no one clicks on the "yes" button the video app closes out after the first pass of the "IF Message" statement or after no response after a pass (or many) within the "Repeat until" phase. With the "Repeat until" function i can't figure out how to set it up using variables and stuff. If i am totally wrong in what i am doing please let me know that also. Thanks.

MEP.bmp

Link to comment
Share on other sites

I'm not 100% sure I understand what you're looking for after a quick read and at the moment I don't have a lot of time to consider it so forgive me if I miss the mark here.

 

You could use a Repeat Until and in the else portion of the If Message toggle a Boolean variable to false and use that for the repeat condition. But I can never remember when the condition is evaluated so I often take a sleazier approach and create and infinite loop (EG Repeat until %var1% does not equal %var1% or repeat a huge number of times if I want a counter) and use the Break or Repeat Exit. You could put that in your Else section.

Link to comment
Share on other sites

I have recently discovered many interesting uses of the "Repeat Until" command, but there is something about it that makes me uncomfortable. It is the most elegant way I know of to repeat a process until a condition is met. But what happens if the condition is never met? For example, if I am hunting for a pixel color along a line, but the developers change the color scheme of the application so that the colors are different, the script will repeat forever.

 

The obvious solution is to increment a counter with each repeat, and exit the loop if the counter value gets too high. But that is exactly how I was doing things before; and in fact, counting repetitions and using "repeat until" at the same time leads to far more complex scripts. I was hoping to simplify my scripts, not make them more opaque!

 

How do others deal with this conundrum?

Link to comment
Share on other sites

Cory, Thanks for the tip. I toyed around with the macro some more and came up with the following...

 

<LAUNCH PROGRAM AND ACTIVATE WINDOW Title="TV" Exact_Match="FALSE" Wildcards="FALSE" Path="C:\\Program Files\\ATI Multimedia\\main\\ATIMMC.EXE" Mode="\x00" Default_Path="TRUE" Wait="1" Wait_For_Program="12"/>
<TEXT TYPE Action="0" Text="<F3>"/> ;removes application window border and screen controls
<WAIT FOR TIME TO ELAPSE Hours="0" Minutes="1" Seconds="0"/>
<VARIABLE SET BOOL Destination="%ANS%" Command="263" Value="FALSE"/>
<REPEAT UNTIL Variable="%ANS%" Condition="\x00" Value="False"/>
<IF MESSAGE Caption="CNN" Message="Are You Still Watching CNN?" BtnMode="\x00" Default="FALSE" Left="Center" Top="Center" Monitor="0" Delay="10"/>
<WAIT FOR TIME TO ELAPSE Hours="0" Minutes="1" Seconds="0"/>
<END IF/>
<END REPEAT/>
<TERMINATE PROCESS Window="FALSE" Name="ATIMMC.EXE" Partial="TRUE" Wildcards="FALSE" Timeout="1000"/>

 

post-4837-127550907042_thumb.jpg

 

To restate the purpose...

 

The macro launches the video app. The video app runs for a period of time and then a pop up message is displayed, "are you still watching?", yes or no. If yes, the video plays for a little while longer. If no, the video app is closed. If "yes" is selected the macro enters a loop where after a period of time the message reappears and asks the "are you still watching" question and will continues to ask that question until there is no response, defaults to "no", exits out of the loop and closes the video app. The macro works if i let it default to "no". If i click "yes" to the message prompt, the macro seems to hang or just not work properly after that. Can you or someone please take a look at what i am doing and tell me where i am going wrong. Thanks.

Link to comment
Share on other sites

Alan, you can use a Repeat Start with "number of times to repeat" set to the value which you consider to be too high. Then, within the loop, you can break out of it by using a Repeat Exit command set to the condition you are looking for.

 

I have recently discovered many interesting uses of the "Repeat Until" command, but there is something about it that makes me uncomfortable. It is the most elegant way I know of to repeat a process until a condition is met. But what happens if the condition is never met? For example, if I am hunting for a pixel color along a line, but the developers change the color scheme of the application so that the colors are different, the script will repeat forever.

 

The obvious solution is to increment a counter with each repeat, and exit the loop if the counter value gets too high. But that is exactly how I was doing things before; and in fact, counting repetitions and using "repeat until" at the same time leads to far more complex scripts. I was hoping to simplify my scripts, not make them more opaque!

 

How do others deal with this conundrum?

Link to comment
Share on other sites

All, I'm running a simple macro illustrated below..

...

The streaming video is brought up and runs for a short period or time. To determine if anyone is still watching the streaming video i display a message box. If the user clicks on the "yes" button in the message box the video app continues to run. After the "wait for time to expire" elapses the video app closes. I want to repeat (loop) this somehow so that as long as the user continues to click on the "yes" button the video app will continue to run. The default response to the "IF Message" is "no". If no one clicks on the "yes" button the video app closes out after the first pass of the "IF Message" statement or after no response after a pass (or many) within the "Repeat until" phase. With the "Repeat until" function i can't figure out how to set it up using variables and stuff. If i am totally wrong in what i am doing please let me know that also. Thanks.

No need for boolean variables, or, indeed, any variables at all!

Repeat Until %n[1]% Does not Equal "%n[1]%"
 If Message "CNN"
   Wait for Time to Elapse
   Continue
 End If
 Repeat Exit
End Repeat

- My Repeat never ends automatically since I have set an impossible condition

- If the response to If Message is Yes, we execute the Wait and Continue commands; this latter command ignores the remaining code in the Repeat loop and restarts the loop

- If the response is no, we execute the Repeat Exit command, which ends the loop

Here's another way of expressing the same idea:

Repeat Until %n[1]% Does not Equal "%n[1]%"
 If Message "CNN"
   Wait for Time to Elapse
 Else
   Repeat Exit
 End If
End Repeat

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...