Loops within Loops.

R

Robert

I have started what is (for me) an ambitious project and
am having trouble visualising a central Procedure.
Deceptively simple, the exact solution eludes me for the
moment. Can someone help with the coding, please?

Sub "RedWord" starts with the one-page Active Document
displayed. The user clicks once on a word. The word is
automatically selected and turned red. Clicks on further
words are made, with the mouse-click starting each new
loop. All the selected words remain red until replaced,
see below. Clicking again on a (now red) word causes it
to revert to its original color, so some sort of toggle
is needed here. (One must allow for a change of mind.)
Realistically we may have 15 - 18 red, single words in
the final displayed document. The sequence of loops ends
when the Return key is pressed.

Parallel with, or after, the above, I need to build up a
string of all the single words finally chosen. However,
the words must first be sorted alphabetically. They are
then joined in a string with a <sp>/<sp> separator
between each (but no separator before the first word or
after the last). In a later Sub this string will be
printed back into the doc, so how do I make it available
to that Sub? In the present Sub it is displayed in a
Message Box when the Return Key terminates the loops.

Finally, after the Message Box has gone, I need to
replace each of the "Redwords" in the text with a series
of underscore characters only partly dependent on the
length of the Redword, as follows:
If Redword is 4 charas long or less, 6 underscores;
If Redword is from 5 - 10 charas, 12 underscores;
If Redword is 11 or more charas, underscores = Length
of Redword + 2 . The underscores, when displayed, should
not be coloured.

I will be most grateful for any help. Thanks a lot.
 
D

DA

Hi Robert

Have you sorted out your word selection/coloring?
What procedures/methods have you tried and where exactly
are you getting stuck.

If you're still trying to get a start, I suggest
something along the following lines. (I've put together
some test code and got your required functionality by
doing the following):

- Build a custom event handler to capture the
WindowBeforeDoubleClick() event.
Once you've got that set up, it's very simple to use the
Selection object to do your word highlighting (e.g. color
change) by simply double-clicking on each required word.

- Capture your words in an array, as this makes it simple
to sort the entries, as well as add remove items when the
WindowBeforeDoubleClick() event is firing.

- Add the array contents to the doc as required
- Search the doc for the red words and replace with
underscores depending on length.

I don't want to bombard you with new code, so it's
probably best if you do another post and answer some of
the above questions.

Regards,
Dennis
 
R

Robert

Hi Dennis,

Many thanks for your reply. I should say that I use this
NGp because I really am a beginner in VBA. I developed
these routines years ago in another language & now need
(in my retirement) to re-code them into VBA to help an
impoverished Third World college. Their English teachers
are rather averse to computers, so everything must be
ultra-simple for the eventual user.

I have been looking at loops, inspired by "Jezebel's"
posts of 8/12/04 (Re: SetText Method Confusion", and
7/7/04 (Re: Is this possible?) which suggest the
selection might be made using For ... Next loops. But I
have tried this without success. VBA cries "Wrong Method"
without saying what it should be.

I don't yet know the WindowBeforeDoubleClick event, but
won't a double-click make the toggling of the selection
process rather difficult? However, a review stage could
be added to overcome this in which the user is asked if
he wants to make any changes to the selected words.

Please don't hesitate to "bombard me with new code."
Like a language-learner, I understand what I read, but
can't always write it myself. Thanks again for your
interest in my problem.

Sincerely, Robert.
 
D

DA

Hi Robert

Send me an email (remove the nospam) and I'll forward you
the test file I was working on. It will be the simplest
way to show you what I meant.

Dennis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top