Reply

Join Date: Apr 2005
Posts: 75
Reputation: purplegerbil is an unknown quantity at this point 
Solved Threads: 6
purplegerbil's Avatar
purplegerbil purplegerbil is offline Offline
Junior Poster in Training

Text Width

 
0
  #1
Sep 8th, 2005
Hi,

Is it possible to measure the width of a line of text saved into a variable.

i.e.
strData = "XXXXXX"
length = 12

strData = "iiiiii"
length = 4

Any font can be used as the data isn't going to be output on screen.

The reason:
I have a csv file holding various names and addresss, I am wanting to find the longest of each of the address fields. I currently have a program that counts the number of characters in a field but I am after the longest in size as well.

XXXX might less characters than iiiiii but it is longer.

Cheers for any help
pG :eek:
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 75
Reputation: purplegerbil is an unknown quantity at this point 
Solved Threads: 6
purplegerbil's Avatar
purplegerbil purplegerbil is offline Offline
Junior Poster in Training

Re: Text Width

 
0
  #2
Sep 9th, 2005
I have got one solution but it is too slow.

Set a label to auto size and copy the data into the label.
check the label.width value.

This works fine but as i said above, its too slow. The application is going to process between 250,000 and 10 million records.

pG
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 121
Reputation: jwshepherd is an unknown quantity at this point 
Solved Threads: 5
jwshepherd's Avatar
jwshepherd jwshepherd is offline Offline
Junior Poster

Re: Text Width

 
0
  #3
Sep 9th, 2005
Debug.Print TextWidth("XXXXX"), TextWidth("iiiii")
.: We may acquire liberty, but it is never recovered if it is lost :.
irc://irc.rizon.net/#itf
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 75
Reputation: purplegerbil is an unknown quantity at this point 
Solved Threads: 6
purplegerbil's Avatar
purplegerbil purplegerbil is offline Offline
Junior Poster in Training

Re: Text Width

 
0
  #4
Sep 12th, 2005
This is the code I am using. This speeds up my app by 50% because the resulst dont need to go to the screen/form.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As POINTAPI) As Long
  2. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
  3.  
  4. Private Type POINTAPI
  5. X As Long
  6. Y As Long
  7. End Type
  8.  
  9. Private Function text_length(Mytext As String) As Long
  10. Dim TextSize As POINTAPI
  11. GetTextExtentPoint32 GetWindowDC(hwnd), Mytext, Len(Mytext), TextSize
  12.  
  13. text_length = TextSize.X
  14. End Function

pG
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC