PC Review


Reply
Thread Tools Rate Thread

ColumnWidths, Characters & Pixels

 
 
Bart
Guest
Posts: n/a
 
      2nd Aug 2007
Dear all,

Adding Column Widths is somehow a very inaccurate matter. I tried to
measure the Width of 5 columns and make an other Column as wide as the
Widths of these 5 columns together. The column appeared to be less
wide.
It seems that the measurements aren't linear. Though I found out that
there's a relation between Characters and Pixels (Characters with the
Standard Font and Size).

m1 (Characters) | m2 (Pixels)
1 12
5 40
10 75
20 145
50 355
100 705

P = 7 * C + 5

P = number of Pixels
C = number of Characters

For example in my case I found the following measurements in
Characters (and Pixels):

2.86 (25 Pixels) +
15.86 (116 Pixels) +
15.86 (116 Pixels) +
15.86 (116 Pixels) +
12.29 (91 Pixels) +
20.14 (146 Pixels)
=82.87 Characters

The sum of these round figures is 82.87 Characters. (They are round
figures as they are when I read them as a Property of a Column.)
The sum of Pixels (not round figures) is 610.

Since the values of the ColumnWidth are round figures the calculation
isn't accurate (and so you might say non-linear). Calculating the
number of Characters with the number of Pixels by using the formula
stated above you get:

610 Pixels ≡ 86.43 Characters,

and not 82.87 Characters as stated above.

To work around this problem is by calculating in Pixels instead of
Characters. First convert the ColumnWidths to Pixels, do the
calculation and then convert it back to Characters. Like this e.g.:

Dim intPixels As Integer
Dim intTotalColumnWidth As Integer
Dim sngTotalColumnWidth As Single

For i = 1 To 3
intPixels = CInt(myRange.Columns(i).ColumnWidth * 7! + 5!)
intTotalColumnWidth = intTotalColumnWidth + intPixels
Next i

sngTotalColumnWidth = CSng(intTotalColumnWidth - 5) / 7!

myRange.Columns(1).ColumnWidth = sngTotalColumnWidth


Does someone have any other suggestions to obtain the ColumnWidth in
Pixels or calculate with ColumnWidths?

Bart

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBCdW5keQ==?=
Guest
Posts: n/a
 
      2nd Aug 2007
First, column widths were not designed for engineering calculations or
anything, they are rounded, you can convert them to pixels and back, but they
will still be rounded. Two things, first, why do you need to base
calculations on the width of cells? and secondly, try looking into just plain
..width, gives points and will likely be a little more accurate than
columnwidth.
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Bart" wrote:

> Dear all,
>
> Adding Column Widths is somehow a very inaccurate matter. I tried to
> measure the Width of 5 columns and make an other Column as wide as the
> Widths of these 5 columns together. The column appeared to be less
> wide.
> It seems that the measurements aren't linear. Though I found out that
> there's a relation between Characters and Pixels (Characters with the
> Standard Font and Size).
>
> m1 (Characters) | m2 (Pixels)
> 1 12
> 5 40
> 10 75
> 20 145
> 50 355
> 100 705
>
> P = 7 * C + 5
>
> P = number of Pixels
> C = number of Characters
>
> For example in my case I found the following measurements in
> Characters (and Pixels):
>
> 2.86 (25 Pixels) +
> 15.86 (116 Pixels) +
> 15.86 (116 Pixels) +
> 15.86 (116 Pixels) +
> 12.29 (91 Pixels) +
> 20.14 (146 Pixels)
> =82.87 Characters
>
> The sum of these round figures is 82.87 Characters. (They are round
> figures as they are when I read them as a Property of a Column.)
> The sum of Pixels (not round figures) is 610.
>
> Since the values of the ColumnWidth are round figures the calculation
> isn't accurate (and so you might say non-linear). Calculating the
> number of Characters with the number of Pixels by using the formula
> stated above you get:
>
> 610 Pixels ≡ 86.43 Characters,
>
> and not 82.87 Characters as stated above.
>
> To work around this problem is by calculating in Pixels instead of
> Characters. First convert the ColumnWidths to Pixels, do the
> calculation and then convert it back to Characters. Like this e.g.:
>
> Dim intPixels As Integer
> Dim intTotalColumnWidth As Integer
> Dim sngTotalColumnWidth As Single
>
> For i = 1 To 3
> intPixels = CInt(myRange.Columns(i).ColumnWidth * 7! + 5!)
> intTotalColumnWidth = intTotalColumnWidth + intPixels
> Next i
>
> sngTotalColumnWidth = CSng(intTotalColumnWidth - 5) / 7!
>
> myRange.Columns(1).ColumnWidth = sngTotalColumnWidth
>
>
> Does someone have any other suggestions to obtain the ColumnWidth in
> Pixels or calculate with ColumnWidths?
>
> Bart
>
>

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      2nd Aug 2007
Check out this link...

http://support.microsoft.com/default.aspx/kb/214123

--
HTH...

Jim Thomlinson


"Bart" wrote:

> Dear all,
>
> Adding Column Widths is somehow a very inaccurate matter. I tried to
> measure the Width of 5 columns and make an other Column as wide as the
> Widths of these 5 columns together. The column appeared to be less
> wide.
> It seems that the measurements aren't linear. Though I found out that
> there's a relation between Characters and Pixels (Characters with the
> Standard Font and Size).
>
> m1 (Characters) | m2 (Pixels)
> 1 12
> 5 40
> 10 75
> 20 145
> 50 355
> 100 705
>
> P = 7 * C + 5
>
> P = number of Pixels
> C = number of Characters
>
> For example in my case I found the following measurements in
> Characters (and Pixels):
>
> 2.86 (25 Pixels) +
> 15.86 (116 Pixels) +
> 15.86 (116 Pixels) +
> 15.86 (116 Pixels) +
> 12.29 (91 Pixels) +
> 20.14 (146 Pixels)
> =82.87 Characters
>
> The sum of these round figures is 82.87 Characters. (They are round
> figures as they are when I read them as a Property of a Column.)
> The sum of Pixels (not round figures) is 610.
>
> Since the values of the ColumnWidth are round figures the calculation
> isn't accurate (and so you might say non-linear). Calculating the
> number of Characters with the number of Pixels by using the formula
> stated above you get:
>
> 610 Pixels ≡ 86.43 Characters,
>
> and not 82.87 Characters as stated above.
>
> To work around this problem is by calculating in Pixels instead of
> Characters. First convert the ColumnWidths to Pixels, do the
> calculation and then convert it back to Characters. Like this e.g.:
>
> Dim intPixels As Integer
> Dim intTotalColumnWidth As Integer
> Dim sngTotalColumnWidth As Single
>
> For i = 1 To 3
> intPixels = CInt(myRange.Columns(i).ColumnWidth * 7! + 5!)
> intTotalColumnWidth = intTotalColumnWidth + intPixels
> Next i
>
> sngTotalColumnWidth = CSng(intTotalColumnWidth - 5) / 7!
>
> myRange.Columns(1).ColumnWidth = sngTotalColumnWidth
>
>
> Does someone have any other suggestions to obtain the ColumnWidth in
> Pixels or calculate with ColumnWidths?
>
> Bart
>
>

 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      3rd Aug 2007
John, Thanks for your interest.
The plain .Width property I tried seems to be a different value than
that of the Width in Pixels. And an other thing is: this .Width
property is read-only.
The fact that I make these calculations is as following. I'm abusing
Excel by trying to store great amounts of text in a Worksheet (more
than those 1024 characters that Excel can handle to show when using
'Wrap Text' and 'AutoSize'. See 'Excel specifications and limits'.) It
subsequently appeared that I should have used Access or at least Word
for what I'm trying to build.
Enfin, I build a Subroutine to place every line of text in a different
row. The text wrapping is done semi-automatic. In a cell as Wide as
the merged cells area I insert word by word. Because 'Wrap Text' and
'AutoSize' are enabled the CellHeight will grow when necessary. I
track this happening and remove the last added word and start a new
line.
In Merged Cells is where I want to put the text. On Merged Cells 'Wrap
Text' doesn't work, so I want to do the job in a single cell with the
same Width. So I have to measure the ColumnWidth of the Merged Cells.
At first when I just added the separate ColumnWidths of the Cells
which the Merged Cells covers, I noticed the Text Wrapping was done
incorrect: the line wasn't fully extended. When doing some debugging I
found out about these inaccurate measurements in Characters as state
in my previous Post.

I don't understand why Microsoft chose to use the Character unit,
since virtually everybody uses proportional Fonts. What meaning does
this unit has to us?

Bart

 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      3rd Aug 2007
Thanks Jim Thomlinson, That put some extra light on the matter after
having read the VBA help files.

Bart

 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      3rd Aug 2007
Sorry, I mixed up. This whole thing hasn't to do anything with round
figures (those should do). It is the offset in the .ColumnWidth that
makes all the trouble: - 5 / 7.

Bart

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Powerpoint scale for wide pixels? (4:3 pixels, 16:9 HDTV) =?Utf-8?B?Qmllbm5pdW0=?= Microsoft Powerpoint 1 13th May 2007 11:37 AM
How do i resize a photo of 320/240 pixels to 240/320 pixels? =?Utf-8?B?QmluZ2Fz?= Microsoft Outlook Discussion 1 28th Nov 2005 04:07 PM
some columns 30 characters 155 pixels others 310 pixels why =?Utf-8?B?dnVyZGVu?= Microsoft Excel Misc 2 26th Apr 2005 03:30 AM
NV40 getting over 7000M pixels/sec (over 7G pixels!) NV55 ATI Video Cards 30 25th Mar 2004 04:26 PM
ColumnWidths Gordon Dale Microsoft Access Form Coding 4 15th Feb 2004 08:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:49 AM.