| | |
Text Width
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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:
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:
Debug.Print TextWidth("XXXXX"), TextWidth("iiiii")
.: We may acquire liberty, but it is never recovered if it is lost :.
irc://irc.rizon.net/#itf
irc://irc.rizon.net/#itf
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.
pG
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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 Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long Private Type POINTAPI X As Long Y As Long End Type Private Function text_length(Mytext As String) As Long Dim TextSize As POINTAPI GetTextExtentPoint32 GetWindowDC(hwnd), Mytext, Len(Mytext), TextSize text_length = TextSize.X End Function
pG
![]() |
Similar Threads
- sign-in to checklogin help (PHP)
- word wrapping (C)
- judtifiying text (C)
- how to add icon to tool bar Python (Python)
- Project calculator (Python)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Picture Size problem
- Next Thread: Crystal REport 9.0
Views: 5097 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





