Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Convert number of characters to twips


Reply
 
Thread Tools Display Modes
  #1  
Old 11-26-2003, 02:28 PM
gablackburn's Avatar
gablackburn gablackburn is offline
Regular
 
Join Date: Aug 2002
Location: Los Angeles, CA
Posts: 53
Question Convert number of characters to twips


I have data loading into a spreadsheet where I'd like to be able to control the width of the first column. I can count the number of characters in all of my rows and select the one value which has the most characters in it.

How can I convert the number of characters into a value of twips?

I know the value of twips/pixel, twips/inch, etc, but I haven't found one for twips/character. I realize the value changes based on the Windows Font Size, but I really haven't found any relevant documention.

Thanks in advance...
GB
Reply With Quote
  #2  
Old 11-26-2003, 02:30 PM
PlenoJure's Avatar
PlenoJure PlenoJure is offline
'With Full Right'

Retired Moderator
* Guru *
 
Join Date: Jun 2003
Posts: 1,880
Default

Maybe the "TextHeight method" & "TextWidth method" (see the MSDN) would be helpful...
__________________
Adam
-- Please use [vb][/vb] tags for code | Posting Guidelines | Please check the MSDN and Search before posting
-- Other Sites: Did you search Google first? | My Blog
Reply With Quote
  #3  
Old 11-26-2003, 03:00 PM
gablackburn's Avatar
gablackburn gablackburn is offline
Regular
 
Join Date: Aug 2002
Location: Los Angeles, CA
Posts: 53
Default

I found this in MSDN, but I don't think it's accurate as the type of font and the font size seems to effect the length... I guess I've answered my own question.

Quote:
vbCharacters 4 Character (horizontal = 120 twips per unit; vertical = 240 twips per unit)
Code:
Private Sub Command1_Click() Dim str As String Dim sing As Single str = Text1.Text sing = Len(str) 'READJUST WIDTH OF TEXTBOX TO ACCOMPANY TEXT Text1.Width = singl * 120 End Sub
Reply With Quote
  #4  
Old 11-26-2003, 03:45 PM
Deadalus Deadalus is offline
Promising Talent

Retired Moderator
* Guru *
 
Join Date: May 2002
Location: Brussels
Posts: 3,601
Default

Quote:
Originally Posted by gablackburn
I guess I've answered my own question.


I don't agree. I think PlenoJure's answer was much more useful. If you set the font of the form to the font you're using, the form's TextWidth property will give you the width that the text needs to print.

Also note that any calculation based on the width of one character is only useful for fixed width fonts.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Numbers BillSoo Tutors' Corner 9 09-09-2006 01:45 PM
Binary files akrocks File I/O and Registry 34 09-11-2003 04:45 PM
Decimal to Binary Conversion hunron General 8 08-08-2003 06:00 PM
pacman ghost AI VB6Newbie Game Programming 23 10-10-2002 08:32 PM
Convert int to a binary number biggoofy01 Miscellaneous Languages 1 03-21-2002 09:22 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->