More on "-1"...
Aug. 12th, 2007 09:12 amI was simply too tired last night to explain why the "- 1" was important in the macro line
By the time we get to this point in the code, we've selected the contents of the table cell we're working with and assigned them to a range called myRange. We've also saved the value of the end point in a variable called myRangeEnd.
If the pattern we're looking for is found, the next step after copying the pattern is to shorten the range to exclude the found pattern. To do this, I wrote code to move the start of the range over by the length of the pattern and then set the end of the range to the original end value.
Schematically, the initial range looks like:
it's time for {123}all{124} good men and women to party
S------------------------------------------------------E
After the first pattern is found, the range is:
it's time for {123}all{124} good men and women to party
S----E
Then we move the start point "over" the end point:
it's time for {123}all{124} good men and women to party
S
And we restore the original end point:
it's time for {123}all{124} good men and women to party
S-----------------------------------E
Only after instrumenting the code to show my selection did I realize what that did. If you work much with Word tables, have you ever noticed what happens if you select text in a cell and go one character past the end? The contents of the entire cell become selected!
That's what was killing me yesterday: everytime the code was executed, the range being examined was being reset to the original range, and I couldn't figure out why.
Extending the end point to one character shy of "the end," i.e., like this:
it's time for {123}all{124} good men and women to party
S----------------------------------E
solved the problem. The next time the pattern is searched for, "{124}" will be found (even if it's at the end of the text).
Apropos of which, the macro works like a charm and actually makes it much easier to deal with the source text. It was a good investment in time.
Cheers...
UPDATE: Wordfast has this concept of a "placeable," which basically is any source text string that's not translatable, such as document designations (e.g., the '50578' in "SSP 50578"). It turns out - I find out by accident - that strings such as "{123}" are treated as placeables as well, and since Wordfast has hotkeys for navigating and copying placeables, it turns out my macro sort of reinvented the wheel. Still, I don't regret the time spent developing the code.
myRange.End = myRangeEnd - 1but not decrementing the value ate a lot of time, so hopefully, this post will reinforce the knowledge gained. (Can you tell I don't want to settle down and translate?)
By the time we get to this point in the code, we've selected the contents of the table cell we're working with and assigned them to a range called myRange. We've also saved the value of the end point in a variable called myRangeEnd.
If the pattern we're looking for is found, the next step after copying the pattern is to shorten the range to exclude the found pattern. To do this, I wrote code to move the start of the range over by the length of the pattern and then set the end of the range to the original end value.
Schematically, the initial range looks like:
it's time for {123}all{124} good men and women to party
S------------------------------------------------------E
After the first pattern is found, the range is:
it's time for {123}all{124} good men and women to party
S----E
Then we move the start point "over" the end point:
it's time for {123}all{124} good men and women to party
S
And we restore the original end point:
it's time for {123}all{124} good men and women to party
S-----------------------------------E
Only after instrumenting the code to show my selection did I realize what that did. If you work much with Word tables, have you ever noticed what happens if you select text in a cell and go one character past the end? The contents of the entire cell become selected!
That's what was killing me yesterday: everytime the code was executed, the range being examined was being reset to the original range, and I couldn't figure out why.
Extending the end point to one character shy of "the end," i.e., like this:
it's time for {123}all{124} good men and women to party
S----------------------------------E
solved the problem. The next time the pattern is searched for, "{124}" will be found (even if it's at the end of the text).
Apropos of which, the macro works like a charm and actually makes it much easier to deal with the source text. It was a good investment in time.
Cheers...
UPDATE: Wordfast has this concept of a "placeable," which basically is any source text string that's not translatable, such as document designations (e.g., the '50578' in "SSP 50578"). It turns out - I find out by accident - that strings such as "{123}" are treated as placeables as well, and since Wordfast has hotkeys for navigating and copying placeables, it turns out my macro sort of reinvented the wheel. Still, I don't regret the time spent developing the code.