954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Font widths question

Thus far I have always chosen the font Courier New because all letters are the same width. Is there any way of determining how "long" a string will be when using other fonts? I would like a way of checking the string's actual length so I can format a printout properly when using fonts that have letters with varying widths.

MrConfused
Light Poster
32 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

What programming language are you using?
You could use

http://us2.php.net/manual/en/function.strlen.php

And then create an if statement to use this display with this font or that display with another font based on length.

Example:

<?php
$str = 'abcdef';
echo strlen($str); 
if ($str >= 5){
?>

<font face="arial">Arial font because its greater then or equal 5</font>

<?
} else {
?>

<font face="tahoma">Tahoma font because its less then 5</font>

<?
}
?>
techniner
Posting Pro
527 posts since May 2005
Reputation Points: 12
Solved Threads: 19
 

You mean this one ?

Private Sub Form_Load()
    Me.FontName = "Verdana"
    MsgBox (Me.TextWidth("Hello"))
End Sub
invisal
Posting Pro
562 posts since Mar 2005
Reputation Points: 350
Solved Threads: 64
 

Man I am two for two today!!

HAHA Posted PHP code in VB just now.. and earlier I posted Javascript in C#

I am calling it a day some one stick a fork in me...

techniner
Posting Pro
527 posts since May 2005
Reputation Points: 12
Solved Threads: 19
 

Yes, TextWidth is the one! Thanks. I should have searched VB help a bit more before posting the question. Oh well.......

MrConfused
Light Poster
32 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You