Jump to content
Macro Express Forums

End A Repeat - Loop


tibolt1

Recommended Posts

Hi. I've a macro that searches through documents, selected pieces of texts and transfers the extracts to a main Document. The macro needs to run usually between 40 -60 times, (it varies), to get to the end of the particular document being processed. Yes they're long documents, like 100 pages.

 

I've tried using a Repeat Until %T1% <> %T1% and a Repeat Start command which puts the macro into a loop. But how do I get the macro to stop dead when it gets to the bottom of the document being processed (because if it continues, it transfers blank entries which mess up the main document).

 

There's a Break command in the Macro - to covers a particular eventuality - but it doesn't stop the macro running in the loop - nor do I want it to.

 

How would you go about this?

 

From reading other posts, ye're experts but I'm a bit of a newbie to this - it's an excellent program though - so you might explain it as if I were a 10 year old!

 

Hope you can help. Thanks.

T.

Link to comment
Share on other sites

Are you able to have your macro determine when it is time to stop? If so you can remove Repeat Until %T1% <> %T1% and add something like:

// Macro commands before the Repeat loop

Variable Set String %T1% ""
Repeat Until %T1% = "STOP_NOW"
 
 // your macro commands go here
 
 // Determine if it is time to stop. You will need to modify this command to suit your needs.
 If Variable %T2% = ""
   // Tell the repeat loop to stop
   Variable Set String %T1% "STOP_NOW"
 End If
Repeat End

// Macro commands after the Repeat loop

Link to comment
Share on other sites

Perhaps a Repeat within a Repeat would solve your problem? The outer Repeat deals with documents or files, while the inner Repeat deals with the lines within a file. You'd then use the Break command to exit the inner loop when you've finished processing a file.

Link to comment
Share on other sites

Kevin,

 

Thanks very much for your reply.

 

My macro works its way down through the document, doing its stuff. I want the macro to stop running when it gets to the end of the document.

 

I could manually add a made up word, e.g MacroStop_Here, at the end of each document that I process, if that's what you mean.

 

I tried this but it doesn't work. I know I need to put something else in but what?

 

Macro Playback Speed: Normal Speed
Variable Set String %T1% ""
Repeat Until %T1% = "STOP_NOW"
 Repeat Start (Repeat 900 times)

// My macro commands go here
   
   Variable Set String %T2% ""
   
     Variable Set String %T1% "STOP_NOW"
   End If
 Repeat End
Repeat End

 

I mentioned that I'm new to this but I've figured out many things - but not variables, as you may guess. I've other macros up and running fine. The programs potential is amazing.

 

Thanks again

T

Link to comment
Share on other sites

I've figured out many things - but not variables
Understanding variables is necessary to understand any solution we describe here. The help contains information about variables but here is a brief description.

 

Variables hold 'stuff'. String variables hold 'strings'. A string is any combination of letters, numbers, and punctuation. It can even hold non-displayable things like Carriage Returns and Linefeeds. Integer variables hold whole numbers. Integer numbers do not have a decimal point. eg '123'. Decimal variables hold numbers that may include a decimal point. Eg '123.456'. Macro commands allow you to set, clear and test variables. This allows a lot of flexibility.

 

Now, to your macro:

 

You need to detect when the macro has reached the end of the document and then tell the repeat loop to stop. If there is something predictable that happens (perhaps a variable is empty) then you can use that to stop the repeat loop. If you do not have another reliable way to detect the end of the document then adding 'MacroStop_Here' to the end of each document would work.

 

Your sample code that has two repeat loops seems wrong to me. The 'STOP_NOW' logic should be within the inner loop. Instead of:

Variable Set String %T1% ""
Repeat Until %T1% = "STOP_NOW"
Repeat Start (Repeat 900 times)

// My macro commands go here
  
  Variable Set String %T2% ""
  
    Variable Set String %T1% "STOP_NOW"
  End If
Repeat End
Repeat End

Perhaps this would work better:

Variable Set String %T1% ""
Repeat Start (Repeat 900 times)
 Variable Set String %T1% ""
 Repeat Until %T1% = "STOP_NOW"

// My macro commands go here
   If Variable %T3% Contains MacroStop_Here
     Variable Set String %T1% "STOP_NOW"
   End If
 Repeat End
Repeat End

I'm not sure why you have the Repeat 900 times. Do you have 900 documents? You probably want to stop the out repeat loop when you run out of documents. If so, then you can use a technique similar to the one described for the inner loop. Another possibility is to use the Repeat With Folder command. This command will repeat once for each file in a folder.

Link to comment
Share on other sites

  In the repeat loops I use... I leave an "out" at the beginning of the loop...

Repeat Until %T1% <> %T1%
Clipboard Copy
Variable Set String %T1% from Clipboard
If Variable %T1% <= "1"
  Macro Stop
End If

//continue coding here
Repeat End

 

When comparing strings like this If Variable %T1% <= "1" you need to remember that a "1" in a string is different than a numeric value of 1. The string "1" is actually the ASCII numeric value that is displayed as 1. The numeric value of "1" is 49.

 

What this means is this:

"/" is less than "1"

"," is less than "1"

"." is less than "1"

"0" is less than "1"

"*" is less than "1"

")" is less than "1"

"(" is less than "1"

"-" is less than "1"

"+" is less than "1"

"&" is less than "1"

BUT

":" is greater than "1"

";" is greater than "1"

"<" is greater than "1"

"=" is greater than "1"

">" is greater than "1"

"?" is greater than "1"

"A" is greater than "1"

"Z" is greater than "1"

"[" is greater than "1"

"\" is greater than "1"

"]" is greater than "1"

"^" is greater than "1"

"_" is greater than "1"

"`" is greater than "1"

"a" is greater than "1"

"z" is greater than "1"

"{" is greater than "1"

"|" is greater than "1"

"}" is greater than "1"

"~" is greater than "1"

 

When a string gets longer, it gets even more confusing.

"0" is less than "01"

but

"01" is greater than "0010"

"0010" is greater than "000001"

 

To be certain that your comparisons are valid, you may want to use integer values like this:

If Variable %N1% <= "1"

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...