Reply to topic  [ 10 posts ] 
how to separate tasks? 
Author Message

Joined: 2009-09-04 13:11:25
Posts: 28
Hi,
I am making a macro consisting of a very long list of "Find and replace". Everything was working fine but now color attributes get sometimes applied to the preceding task. What should I do to prevent this? Is there a command to separate tasks?


2009-11-12 20:38:56
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Hi Pat- I'm not sure I understand exactly what you're saying. Do you mean that parts of the text/code in your macro file have improperly changed color somehow? Macro files are like any other document, meaning you can have different fonts/colors/attributes applied to different pieces of the document.


2009-11-13 13:19:49
Profile WWW

Joined: 2009-09-04 13:11:25
Posts: 28
I fixed the problem I had this morning (I don't know why it works now but it works). The macro is so long that it is not surprising that this kind of problem arises since I did not know anything about macros just a few weeks ago. My macro is composed of dozens of simple components. I was wondering: do you think it would be easier to transform those components in smaller macros and then create a list of those components in an other macro? Thank you for your help.


2009-11-13 14:47:42
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
You could take that approach, of splitting up your macro into multiple macros, and then calling those smaller macros from some master macro. I think that only makes sense if the smaller sub-tasks are meaningful on their own, but it's really a matter of personal taste and organization. Do whatever works best for your brain!


2009-11-13 15:47:15
Profile WWW

Joined: 2009-09-04 13:11:25
Posts: 28
Hi again,

I think I know now why sometime things go wrong but I don't know how to fix it. I have a master macro who runs dozens of macros in a certain order. Individually, the small macros are working fine. However, when I get the master macro running, if one of the small macros doesn't find in the text the string of characters it is supposed to modify, it modifies the string of the previous macro. Is there a way I can prevent this to happen?

Thank you


2009-12-05 22:48:02
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Hi, Pat.

Have you set Find and Replace to operate in selection and to keep selection (something like Find and Replace “abc”, “def”, “sS”)? If so, a macro line is bound to process whatever was left selected in the previous line(s).

It would be interesting to see the macro itself. Even a few lines would be of help.

Cheers, Henry.


2009-12-06 01:03:32
Profile

Joined: 2009-09-04 13:11:25
Posts: 28
Hi Henry

Here is an example,

Find all 'a', 'Eam'
$color = Color.newWithHexTriplet 'FFCC00'
Set Text Color $color

Pat


2009-12-06 12:48:10
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
Hi Pat,

you can prevent the problem if you make the code conditional on the actual finding of the text. You can modify your code like this:

Code:
If Find all 'a', 'Eam'
$color = Color.newWithHexTriplet 'FFCC00'
Set Text Color $color
end


Note that I put an "if" on the line with the find, and and "end" after the other instructions. Now the lines in between will only execute if the find instruction actually finds something.

hope this helps
philip

_________________
philip


2009-12-07 01:21:24
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Ah, I see now.

This is a common mistake. Performing a macro is like executing a series of commands in a row. When you operate a search, either via a macro or the Find/Replace window, the program leaves all found/replaced text selected.

Now, suppose all your b's in a document are selected as a result of a previous Find and Replace command, and you go on searching all of the f's because you want apply them the color red. Suppose, also, that there are no f's in your document. Then the macro will go on to the next step, and will apply a color red to whatever is selected. That's why you'll end up with all your b's, not f's, colored red – because the Find and Replace command didn't change the selections.

Here you have two ways.

1. An if pattern, as explained by Philip.
2. A Find and Replace command of this kind:
Code:
Find and Replace "re", "\\0", "aEmU"
(Where re is a regular expression.)

Once you have written this line, select it and remove all attributes via Format > Remove Attributes and Style. Then select \0 and go to Format > Text Color > Show Text Colors and pick a color from the system color picker.

I hope this helps.

Cheers, Henry.


2009-12-07 06:08:52
Profile

Joined: 2009-09-04 13:11:25
Posts: 28
Thank you very much.

Pat


2009-12-07 06:55:00
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software