An easy question (hopefully) about text length. Thanks!

J

JOCA

Folks,

I am trying to determine programmatically the length (in inches, pixels or
any distance measure) of a given text selection (or line). For example:
THE QUICK BROWN FOX. . when typed in capitalized letters takes more
screen space than.
the quick brown fox . when typed in lower caps. Also, the bold version
of it
the quick brown fox .takes a little more screen space than the non-bold
version..


The above is also true for text strings containing different characters. For
example:
Mmmmmmmmmm . takes more screen space than
iiiiiiiiii


So far I know how to get the length of a selected text (in characters) using
the following line:

Selection.Characters.Count

Can someone tell me how to get the length (distance) of a given text line in
the screen ? I don't care if it is in inches, pixels, or centimeters.

Thanks in advance.

JOCA
 
M

Madhukar

HI JOCA,

you prblem is not clear.
You want to get the distance of you text in screen or from
some location of document.
coz measuring distance in screen and in document is
different.
With regrds madhukar
 
H

Helmut Weber

Hi Joca,
you might try this:
Select the text.
Start a Makro that:
1. puts the text in a variable
2. collapses the cursor to the left.
3. Get Selection.Information(7) ' eg. into pos1
4. search for the text
5. Collapse the cursor to the right.
6. Get Selection.Information(7) ' eg. into pos2
pos2 - pos1 is the width of the selection,
if the selection restes on one (!) line.
pos2 - pos1 is the textwidth in Twips
20 Twip = 1 Point, 72 Point = 1 Inch
Greetings from Bavaria, Germany
Helmut Weber
(using Word 97)
wdHorizontalPositionRelativeToTextBoundary = 7 !!!
 
R

Roy Lasris

I have a example of why the information as to the 'size' of a group of
characters would be helpful. I have creating a userform which APPEARS to
contain two columns of text preceded by a checkbox. Actually, it is a checkbox,
with the checkbox caption being a concantenation of two separate text items (a
name and a subject) with a calculated number of tabs added between text1 and
text2. I want the second (subject) 'column' to start as reasonably close as
possible to the first column, but an appearance of columns must be preserved.

The formula I use to calculate each checkboxes caption is simply:
checkbox(x) = _
IIF(len(text1) < 20, text1 & chr(9) & chr(9) & text2, text1 & chr(9) & text2).

I.e., if text1 is short, add two tabs, if it is long, add just one tab. That
way I have the best shot (statistically) of lining things up in the second
column. (The 20 characters I chose as the word width is an average obtained
after experimentation, but I would sure like to know the actual width of text
to allow more precise alignment. As the initial question posed, 20 m's would
substantially exceed the width of 20 i's.

Here is an example. (T1, etc., indicate tab positions. I am shrinking the
len to '5' (not '20') for sake of space, but otherwise the above example
applies.):
T1 T2 T3
iiiiii Subject of this line (5)
mimim Subject of this line (5)
mmmmm Subject of this line (5)
iiiiiiii Subject of this line(8)
mimimim Subject of this line (8)

In the first three lines, two tabs were added in accordance with the
formula; one tab was added for the fourth and fifth lines. Nothing aligns. If I
knew the width of each text1, I could do the alignment more precisely.

I love the question posed by Joca, and hope there is a solution.

Roy
 
W

Word Heretic

G'day (e-mail address removed) (Roy Lasris),

Range.Information(lotsa good stuff)


(e-mail address removed) (Roy Lasris) was spinning this yarn:
I have a example of why the information as to the 'size' of a group of
characters would be helpful. I have creating a userform which APPEARS to
contain two columns of text preceded by a checkbox. Actually, it is a checkbox,
with the checkbox caption being a concantenation of two separate text items (a
name and a subject) with a calculated number of tabs added between text1 and
text2. I want the second (subject) 'column' to start as reasonably close as
possible to the first column, but an appearance of columns must be preserved.

The formula I use to calculate each checkboxes caption is simply:
checkbox(x) = _
IIF(len(text1) < 20, text1 & chr(9) & chr(9) & text2, text1 & chr(9) & text2).

I.e., if text1 is short, add two tabs, if it is long, add just one tab. That
way I have the best shot (statistically) of lining things up in the second
column. (The 20 characters I chose as the word width is an average obtained
after experimentation, but I would sure like to know the actual width of text
to allow more precise alignment. As the initial question posed, 20 m's would
substantially exceed the width of 20 i's.

Here is an example. (T1, etc., indicate tab positions. I am shrinking the
len to '5' (not '20') for sake of space, but otherwise the above example
applies.):
T1 T2 T3
iiiiii Subject of this line (5)
mimim Subject of this line (5)
mmmmm Subject of this line (5)
iiiiiiii Subject of this line(8)
mimimim Subject of this line (8)

In the first three lines, two tabs were added in accordance with the
formula; one tab was added for the fourth and fifth lines. Nothing aligns. If I
knew the width of each text1, I could do the alignment more precisely.

I love the question posed by Joca, and hope there is a solution.

Roy

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email: (e-mail address removed)
Products: http://www.geocities.com/word_heretic/products.html
Spellbooks: 728 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.
 
K

Klaus Linke

Hi Roy,

I'd use two sets of labels in two columns. Or change the font from "Tahoma"
to a non-proportional font like "Andale Mono" or "Courier New" (where "i"
and "m" need the same space).

In User Forms, the .Information property won't help you, I think.

Regards,
Klaus
 
R

Roy Lasris

Thanks, Klaus. Unfortunately the .information applies onto to the text in the
document. I have tried the monospaced font before, but, not surprisingly, it
just doen't look as good. Oh well, maybe a year from now Microsoft will give us
a way to do this. Thanks again.
Roy
 

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